@scratch/scratch-render 11.0.0-UEPR-176

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/LICENSE +12 -0
  2. package/README.md +87 -0
  3. package/dist/node/scratch-render.js +2 -0
  4. package/dist/node/scratch-render.js.LICENSE.txt +3 -0
  5. package/dist/web/scratch-render.js +3 -0
  6. package/dist/web/scratch-render.js.LICENSE.txt +14 -0
  7. package/dist/web/scratch-render.js.map +1 -0
  8. package/dist/web/scratch-render.min.js +3 -0
  9. package/dist/web/scratch-render.min.js.LICENSE.txt +14 -0
  10. package/dist/web/scratch-render.min.js.map +1 -0
  11. package/package.json +89 -0
  12. package/src/.eslintrc.js +11 -0
  13. package/src/BitmapSkin.js +120 -0
  14. package/src/Drawable.js +734 -0
  15. package/src/EffectTransform.js +197 -0
  16. package/src/PenSkin.js +350 -0
  17. package/src/Rectangle.js +196 -0
  18. package/src/RenderConstants.js +34 -0
  19. package/src/RenderWebGL.js +2029 -0
  20. package/src/SVGSkin.js +239 -0
  21. package/src/ShaderManager.js +187 -0
  22. package/src/Silhouette.js +257 -0
  23. package/src/Skin.js +235 -0
  24. package/src/TextBubbleSkin.js +284 -0
  25. package/src/index.js +7 -0
  26. package/src/playground/.eslintrc.js +9 -0
  27. package/src/playground/getMousePosition.js +37 -0
  28. package/src/playground/index.html +41 -0
  29. package/src/playground/playground.js +202 -0
  30. package/src/playground/queryPlayground.html +73 -0
  31. package/src/playground/queryPlayground.js +196 -0
  32. package/src/playground/style.css +11 -0
  33. package/src/shaders/sprite.frag +249 -0
  34. package/src/shaders/sprite.vert +75 -0
  35. package/src/util/canvas-measurement-provider.js +41 -0
  36. package/src/util/color-conversions.js +97 -0
  37. package/src/util/log.js +4 -0
  38. package/src/util/text-wrapper.js +112 -0
@@ -0,0 +1,14 @@
1
+ /* @license twgl.js 4.24.0 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
2
+ Available via the MIT license.
3
+ see: http://github.com/greggman/twgl.js for details */
4
+
5
+ /*!
6
+ * The buffer module from node.js, for the browser.
7
+ *
8
+ * @author Feross Aboukhadijeh <http://feross.org>
9
+ * @license MIT
10
+ */
11
+
12
+ /*! @license DOMPurify 3.2.4 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.4/LICENSE */
13
+
14
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scratch-render.min.js","mappings":";AAAA","sources":["webpack://ScratchRender/webpack/universalModuleDefinition"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"ScratchRender\"] = factory();\n\telse\n\t\troot[\"ScratchRender\"] = factory();\n})(self, function() {\nreturn "],"names":[],"sourceRoot":""}
package/package.json ADDED
@@ -0,0 +1,89 @@
1
+ {
2
+ "name": "@scratch/scratch-render",
3
+ "version": "11.0.0-UEPR-176",
4
+ "description": "WebGL Renderer for Scratch 3.0",
5
+ "author": "Massachusetts Institute of Technology",
6
+ "license": "AGPL-3.0-only",
7
+ "homepage": "https://github.com/scratchfoundation/scratch-render#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/scratchfoundation/scratch-editor.git"
11
+ },
12
+ "main": "./dist/node/scratch-render.js",
13
+ "exports": {
14
+ "webpack": "./src/index.js",
15
+ "browser": "./dist/web/scratch-render.js",
16
+ "node": "./dist/node/scratch-render.js",
17
+ "default": "./src/index.js"
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "src"
22
+ ],
23
+ "scripts": {
24
+ "build": "webpack --progress && npm run docs",
25
+ "clean": "rimraf dist playground",
26
+ "docs": "jsdoc -c .jsdoc.json",
27
+ "lint": "eslint .",
28
+ "prepublish": "npm run build",
29
+ "prepublish-watch": "npm run watch",
30
+ "start": "webpack-dev-server",
31
+ "tap": "tap test/unit test/integration",
32
+ "test": "npm run lint && npm run tap",
33
+ "watch": "webpack --progress --watch --watch-poll"
34
+ },
35
+ "tap": {
36
+ "branches": 10,
37
+ "functions": 20,
38
+ "lines": 30,
39
+ "statements": 30
40
+ },
41
+ "browserslist": [
42
+ "Chrome >= 63",
43
+ "Edge >= 15",
44
+ "Firefox >= 57",
45
+ "Safari >= 8",
46
+ "Android >= 63",
47
+ "iOS >= 8"
48
+ ],
49
+ "dependencies": {
50
+ "@scratch/scratch-svg-renderer": "11.0.0-UEPR-176",
51
+ "grapheme-breaker": "0.3.2",
52
+ "hull.js": "0.2.10",
53
+ "ify-loader": "1.1.0",
54
+ "linebreak": "0.3.0",
55
+ "minilog": "3.1.0",
56
+ "raw-loader": "0.5.1",
57
+ "twgl.js": "4.24.0"
58
+ },
59
+ "peerDependencies": {
60
+ "scratch-render-fonts": "^1.0.0"
61
+ },
62
+ "devDependencies": {
63
+ "@babel/core": "7.26.10",
64
+ "@babel/eslint-parser": "7.26.10",
65
+ "@babel/polyfill": "7.12.1",
66
+ "@babel/preset-env": "7.26.9",
67
+ "@scratch/scratch-vm": "11.0.0-UEPR-176",
68
+ "babel-loader": "9.2.1",
69
+ "copy-webpack-plugin": "4.6.0",
70
+ "docdash": "0.4.0",
71
+ "eslint": "8.57.1",
72
+ "eslint-config-scratch": "9.0.9",
73
+ "gh-pages": "1.2.0",
74
+ "html-webpack-plugin": "5.6.3",
75
+ "jsdoc": "3.6.11",
76
+ "json": "9.0.6",
77
+ "playwright-chromium": "1.51.1",
78
+ "scratch-render-fonts": "1.0.177",
79
+ "scratch-semantic-release-config": "3.0.0",
80
+ "scratch-storage": "4.0.89",
81
+ "scratch-webpack-configuration": "3.0.0",
82
+ "semantic-release": "19.0.5",
83
+ "tap": "16.3.10",
84
+ "terser-webpack-plugin": "5.3.14",
85
+ "webpack": "5.98.0",
86
+ "webpack-cli": "5.1.4",
87
+ "webpack-dev-server": "5.2.0"
88
+ }
89
+ }
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+ root: true,
3
+ extends: ['scratch', 'scratch/es6', 'scratch/node'],
4
+ env: {
5
+ node: false,
6
+ browser: true // TODO: disable this
7
+ },
8
+ globals: {
9
+ Buffer: true // TODO: remove this?
10
+ }
11
+ };
@@ -0,0 +1,120 @@
1
+ const twgl = require('twgl.js');
2
+
3
+ const Skin = require('./Skin');
4
+
5
+ class BitmapSkin extends Skin {
6
+ /**
7
+ * Create a new Bitmap Skin.
8
+ * @extends Skin
9
+ * @param {!int} id - The ID for this Skin.
10
+ * @param {!RenderWebGL} renderer - The renderer which will use this skin.
11
+ */
12
+ constructor (id, renderer) {
13
+ super(id);
14
+
15
+ /** @type {!int} */
16
+ this._costumeResolution = 1;
17
+
18
+ /** @type {!RenderWebGL} */
19
+ this._renderer = renderer;
20
+
21
+ /** @type {Array<int>} */
22
+ this._textureSize = [0, 0];
23
+ }
24
+
25
+ /**
26
+ * Dispose of this object. Do not use it after calling this method.
27
+ */
28
+ dispose () {
29
+ if (this._texture) {
30
+ this._renderer.gl.deleteTexture(this._texture);
31
+ this._texture = null;
32
+ }
33
+ super.dispose();
34
+ }
35
+
36
+ /**
37
+ * @return {Array<number>} the "native" size, in texels, of this skin.
38
+ */
39
+ get size () {
40
+ return [this._textureSize[0] / this._costumeResolution, this._textureSize[1] / this._costumeResolution];
41
+ }
42
+
43
+ /**
44
+ * @param {Array<number>} scale - The scaling factors to be used.
45
+ * @return {WebGLTexture} The GL texture representation of this skin when drawing at the given scale.
46
+ */
47
+ // eslint-disable-next-line no-unused-vars
48
+ getTexture (scale) {
49
+ return this._texture || super.getTexture();
50
+ }
51
+
52
+ /**
53
+ * Set the contents of this skin to a snapshot of the provided bitmap data.
54
+ * @param {ImageData|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} bitmapData - new contents for this skin.
55
+ * @param {int} [costumeResolution=1] - The resolution to use for this bitmap.
56
+ * @param {Array<number>} [rotationCenter] - Optional rotation center for the bitmap. If not supplied, it will be
57
+ * calculated from the bounding box
58
+ * @fires Skin.event:WasAltered
59
+ */
60
+ setBitmap (bitmapData, costumeResolution, rotationCenter) {
61
+ if (!bitmapData.width || !bitmapData.height) {
62
+ super.setEmptyImageData();
63
+ return;
64
+ }
65
+ const gl = this._renderer.gl;
66
+
67
+ // Preferably bitmapData is ImageData. ImageData speeds up updating
68
+ // Silhouette and is better handled by more browsers in regards to
69
+ // memory.
70
+ let textureData = bitmapData;
71
+ if (bitmapData instanceof HTMLCanvasElement) {
72
+ // Given a HTMLCanvasElement get the image data to pass to webgl and
73
+ // Silhouette.
74
+ const context = bitmapData.getContext('2d');
75
+ textureData = context.getImageData(0, 0, bitmapData.width, bitmapData.height);
76
+ }
77
+
78
+ if (this._texture === null) {
79
+ const textureOptions = {
80
+ auto: false,
81
+ wrap: gl.CLAMP_TO_EDGE
82
+ };
83
+
84
+ this._texture = twgl.createTexture(gl, textureOptions);
85
+ }
86
+
87
+ this._setTexture(textureData);
88
+
89
+ // Do these last in case any of the above throws an exception
90
+ this._costumeResolution = costumeResolution || 2;
91
+ this._textureSize = BitmapSkin._getBitmapSize(bitmapData);
92
+
93
+ if (typeof rotationCenter === 'undefined') rotationCenter = this.calculateRotationCenter();
94
+ this._rotationCenter[0] = rotationCenter[0];
95
+ this._rotationCenter[1] = rotationCenter[1];
96
+
97
+ this.emit(Skin.Events.WasAltered);
98
+ }
99
+
100
+ /**
101
+ * @param {ImageData|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} bitmapData - bitmap data to inspect.
102
+ * @returns {Array<int>} the width and height of the bitmap data, in pixels.
103
+ * @private
104
+ */
105
+ static _getBitmapSize (bitmapData) {
106
+ if (bitmapData instanceof HTMLImageElement) {
107
+ return [bitmapData.naturalWidth || bitmapData.width, bitmapData.naturalHeight || bitmapData.height];
108
+ }
109
+
110
+ if (bitmapData instanceof HTMLVideoElement) {
111
+ return [bitmapData.videoWidth || bitmapData.width, bitmapData.videoHeight || bitmapData.height];
112
+ }
113
+
114
+ // ImageData or HTMLCanvasElement
115
+ return [bitmapData.width, bitmapData.height];
116
+ }
117
+
118
+ }
119
+
120
+ module.exports = BitmapSkin;