p5 2.0.0 → 2.0.1

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 (188) hide show
  1. package/{src → dist}/accessibility/color_namer.js +48 -3
  2. package/{src → dist}/accessibility/describe.js +2 -2
  3. package/{src → dist}/accessibility/gridOutput.js +2 -2
  4. package/dist/accessibility/index.js +60 -0
  5. package/{src → dist}/accessibility/outputs.js +2 -2
  6. package/{src → dist}/accessibility/textOutput.js +2 -2
  7. package/dist/app.js +120 -0
  8. package/{src → dist}/color/color_conversion.js +48 -10
  9. package/{src → dist}/color/color_spaces/hsb.js +3 -1
  10. package/dist/color/creating_reading.js +3 -0
  11. package/dist/color/index.js +13 -0
  12. package/dist/color/p5.Color.culori.js +1 -0
  13. package/dist/color/p5.Color.js +3 -0
  14. package/{src → dist}/color/setting.js +9 -6
  15. package/{src/core/constants.js → dist/constants-C-g_eAdC.js} +266 -130
  16. package/{src → dist}/core/States.js +3 -1
  17. package/dist/core/constants.js +1 -0
  18. package/{src → dist}/core/environment.js +7 -6
  19. package/{src → dist}/core/friendly_errors/browser_errors.js +1 -1
  20. package/{src → dist}/core/friendly_errors/fes_core.js +14 -44
  21. package/{src → dist}/core/friendly_errors/file_errors.js +6 -3
  22. package/dist/core/friendly_errors/index.js +23 -0
  23. package/dist/core/friendly_errors/param_validator.js +5455 -0
  24. package/{src → dist}/core/friendly_errors/sketch_reader.js +50 -4
  25. package/{src → dist}/core/friendly_errors/sketch_verifier.js +6 -6
  26. package/{src → dist}/core/friendly_errors/stacktrace.js +3 -5
  27. package/{src → dist}/core/friendly_errors/validate_params.js +50 -41
  28. package/{src → dist}/core/helpers.js +9 -6
  29. package/dist/core/init.js +105 -0
  30. package/dist/core/internationalization.js +302 -0
  31. package/dist/core/legacy.js +73 -0
  32. package/dist/core/main.js +44 -0
  33. package/dist/core/noop.js +3 -0
  34. package/dist/core/p5.Graphics.js +40 -0
  35. package/dist/core/p5.Renderer.js +11 -0
  36. package/dist/core/p5.Renderer2D.js +44 -0
  37. package/dist/core/reference.js +1 -0
  38. package/dist/core/rendering.js +40 -0
  39. package/{src → dist}/core/structure.js +3 -3
  40. package/{src → dist}/core/transform.js +2 -2
  41. package/{src/color/creating_reading.js → dist/creating_reading-D4AAKRbx.js} +841 -13
  42. package/{src → dist}/data/index.js +3 -1
  43. package/{src → dist}/data/local_storage.js +2 -8
  44. package/{src → dist}/dom/dom.js +11 -5
  45. package/dist/dom/index.js +18 -0
  46. package/{src → dist}/dom/p5.Element.js +14 -12
  47. package/{src → dist}/dom/p5.File.js +4 -4
  48. package/{src → dist}/dom/p5.MediaElement.js +10 -4
  49. package/{src → dist}/events/acceleration.js +2 -2
  50. package/{src → dist}/events/index.js +3 -1
  51. package/{src → dist}/events/keyboard.js +14 -11
  52. package/{src → dist}/events/pointer.js +16 -17
  53. package/dist/image/const.js +9 -0
  54. package/{src → dist}/image/filterRenderer2D.js +57 -37
  55. package/{src → dist}/image/filters.js +1 -3
  56. package/dist/image/image.js +40 -0
  57. package/dist/image/index.js +51 -0
  58. package/dist/image/loading_displaying.js +40 -0
  59. package/dist/image/p5.Image.js +11 -0
  60. package/{src → dist}/image/pixels.js +4 -3
  61. package/{src → dist}/io/csv.js +72 -70
  62. package/dist/io/files.js +40 -0
  63. package/dist/io/index.js +51 -0
  64. package/{src → dist}/io/p5.Table.js +6 -6
  65. package/{src → dist}/io/p5.TableRow.js +3 -4
  66. package/{src → dist}/io/p5.XML.js +2 -5
  67. package/{src → dist}/io/utilities.js +1 -1
  68. package/{src/core/p5.Renderer2D.js → dist/main-s72KWcUy.js} +735 -57
  69. package/{src → dist}/math/Matrices/Matrix.js +10 -8
  70. package/{src → dist}/math/Matrices/MatrixInterface.js +5 -3
  71. package/{src → dist}/math/Matrices/MatrixNumjs.js +12 -26
  72. package/{src → dist}/math/calculation.js +2 -2
  73. package/{src → dist}/math/index.js +6 -3
  74. package/{src → dist}/math/math.js +2 -2
  75. package/{src → dist}/math/noise.js +2 -2
  76. package/{src → dist}/math/p5.Matrix.js +7 -4
  77. package/{src → dist}/math/p5.Vector.js +6 -6
  78. package/{src → dist}/math/random.js +2 -2
  79. package/{src → dist}/math/trigonometry.js +16 -15
  80. package/{src/image/p5.Image.js → dist/p5.Renderer-CwAYZOC2.js} +390 -19
  81. package/dist/rendering--aAe5aq3.js +24925 -0
  82. package/{src → dist}/shape/2d_primitives.js +18 -17
  83. package/{src → dist}/shape/attributes.js +18 -17
  84. package/{src → dist}/shape/curves.js +2 -2
  85. package/{src → dist}/shape/custom_shapes.js +44 -64
  86. package/{src → dist}/shape/index.js +10 -2
  87. package/{src → dist}/shape/vertex.js +2 -3
  88. package/dist/type/index.js +25 -0
  89. package/{src → dist}/type/lib/Typr.js +76 -94
  90. package/{src → dist}/type/p5.Font.js +37 -61
  91. package/{src → dist}/type/textCore.js +34 -57
  92. package/{src → dist}/type/unicodeRanges.js +3 -1
  93. package/{src → dist}/utilities/conversion.js +2 -2
  94. package/{src → dist}/utilities/index.js +3 -1
  95. package/{src → dist}/utilities/time_date.js +6 -7
  96. package/{src → dist}/utilities/utility_functions.js +2 -2
  97. package/dist/webgl/3d_primitives.js +40 -0
  98. package/{src → dist}/webgl/GeometryBufferCache.js +3 -1
  99. package/{src → dist}/webgl/GeometryBuilder.js +12 -8
  100. package/{src → dist}/webgl/ShaderGenerator.js +79 -82
  101. package/{src → dist}/webgl/ShapeBuilder.js +26 -23
  102. package/dist/webgl/index.js +76 -0
  103. package/{src → dist}/webgl/interaction.js +7 -6
  104. package/dist/webgl/light.js +40 -0
  105. package/{src → dist}/webgl/loading.js +45 -12
  106. package/dist/webgl/material.js +40 -0
  107. package/dist/webgl/p5.Camera.js +40 -0
  108. package/{src → dist}/webgl/p5.DataArray.js +3 -5
  109. package/dist/webgl/p5.Framebuffer.js +40 -0
  110. package/{src → dist}/webgl/p5.Geometry.js +12 -15
  111. package/{src → dist}/webgl/p5.Quat.js +5 -4
  112. package/{src → dist}/webgl/p5.RenderBuffer.js +2 -3
  113. package/dist/webgl/p5.RendererGL.js +40 -0
  114. package/dist/webgl/p5.Shader.js +40 -0
  115. package/dist/webgl/p5.Texture.js +40 -0
  116. package/{src → dist}/webgl/text.js +51 -9
  117. package/lib/p5.esm.js +102 -48
  118. package/lib/p5.js +102 -48
  119. package/lib/p5.min.js +1 -1
  120. package/package.json +17 -16
  121. package/translations/dev.js +6 -6
  122. package/translations/index.js +1 -1
  123. package/src/README.md +0 -27
  124. package/src/accessibility/index.js +0 -13
  125. package/src/app.js +0 -61
  126. package/src/color/index.js +0 -9
  127. package/src/color/p5.Color.culori.js +0 -66
  128. package/src/color/p5.Color.js +0 -851
  129. package/src/core/README.md +0 -91
  130. package/src/core/friendly_errors/index.js +0 -13
  131. package/src/core/friendly_errors/param_validator.js +0 -561
  132. package/src/core/init.js +0 -58
  133. package/src/core/internationalization.js +0 -195
  134. package/src/core/legacy.js +0 -29
  135. package/src/core/main.js +0 -689
  136. package/src/core/noop.js +0 -1
  137. package/src/core/p5.Graphics.js +0 -696
  138. package/src/core/p5.Renderer.js +0 -408
  139. package/src/core/reference.js +0 -2060
  140. package/src/core/rendering.js +0 -697
  141. package/src/dom/index.js +0 -11
  142. package/src/image/const.js +0 -6
  143. package/src/image/image.js +0 -731
  144. package/src/image/index.js +0 -15
  145. package/src/image/loading_displaying.js +0 -1431
  146. package/src/io/files.js +0 -2210
  147. package/src/io/index.js +0 -11
  148. package/src/math/README.md +0 -40
  149. package/src/type/index.js +0 -9
  150. package/src/webgl/3d_primitives.js +0 -2741
  151. package/src/webgl/index.js +0 -37
  152. package/src/webgl/light.js +0 -1851
  153. package/src/webgl/material.js +0 -3854
  154. package/src/webgl/p5.Camera.js +0 -4010
  155. package/src/webgl/p5.Framebuffer.js +0 -1865
  156. package/src/webgl/p5.RendererGL.js +0 -2867
  157. package/src/webgl/p5.Shader.js +0 -1505
  158. package/src/webgl/p5.Texture.js +0 -541
  159. package/src/webgl/shaders/basic.frag +0 -6
  160. package/src/webgl/shaders/filters/base.frag +0 -22
  161. package/src/webgl/shaders/filters/base.vert +0 -19
  162. package/src/webgl/shaders/filters/blur.frag +0 -60
  163. package/src/webgl/shaders/filters/default.vert +0 -18
  164. package/src/webgl/shaders/filters/dilate.frag +0 -39
  165. package/src/webgl/shaders/filters/erode.frag +0 -39
  166. package/src/webgl/shaders/filters/gray.frag +0 -16
  167. package/src/webgl/shaders/filters/invert.frag +0 -15
  168. package/src/webgl/shaders/filters/opaque.frag +0 -12
  169. package/src/webgl/shaders/filters/posterize.frag +0 -29
  170. package/src/webgl/shaders/filters/threshold.frag +0 -23
  171. package/src/webgl/shaders/font.frag +0 -216
  172. package/src/webgl/shaders/font.vert +0 -44
  173. package/src/webgl/shaders/imageLight.vert +0 -33
  174. package/src/webgl/shaders/imageLightDiffused.frag +0 -82
  175. package/src/webgl/shaders/imageLightSpecular.frag +0 -134
  176. package/src/webgl/shaders/light.vert +0 -37
  177. package/src/webgl/shaders/light_texture.frag +0 -26
  178. package/src/webgl/shaders/lighting.glsl +0 -227
  179. package/src/webgl/shaders/line.frag +0 -74
  180. package/src/webgl/shaders/line.vert +0 -294
  181. package/src/webgl/shaders/normal.frag +0 -6
  182. package/src/webgl/shaders/normal.vert +0 -72
  183. package/src/webgl/shaders/phong.frag +0 -84
  184. package/src/webgl/shaders/phong.vert +0 -87
  185. package/src/webgl/shaders/point.frag +0 -29
  186. package/src/webgl/shaders/point.vert +0 -19
  187. package/src/webgl/shaders/sphereMapping.frag +0 -26
  188. package/src/webgl/shaders/webgl2Compatibility.glsl +0 -34
package/src/core/init.js DELETED
@@ -1,58 +0,0 @@
1
- import p5 from '../core/main';
2
- import { initialize as initTranslator } from './internationalization';
3
-
4
- /**
5
- * This file setup global mode automatic instantiation
6
- *
7
- * if sketch is on window
8
- * assume "global" mode
9
- * and instantiate p5 automatically
10
- * otherwise do nothing
11
- *
12
- * @private
13
- * @return {Undefined}
14
- */
15
- export const _globalInit = () => {
16
- // Could have been any property defined within the p5 constructor.
17
- // If that property is already a part of the global object,
18
- // this code has already run before, likely due to a duplicate import
19
- if (typeof window._setupDone !== 'undefined') {
20
- console.warn(
21
- 'p5.js seems to have been imported multiple times. Please remove the duplicate import'
22
- );
23
- return;
24
- }
25
-
26
- if (!window.mocha) {
27
- const p5ReadyEvent = new Event('p5Ready');
28
- window.dispatchEvent(p5ReadyEvent);
29
-
30
- // If there is a setup or draw function on the window
31
- // then instantiate p5 in "global" mode
32
- if (
33
- ((window.setup && typeof window.setup === 'function') ||
34
- (window.draw && typeof window.draw === 'function')) &&
35
- !p5.instance
36
- ) {
37
- new p5();
38
- }
39
- }
40
- };
41
-
42
- // make a promise that resolves when the document is ready
43
- export const waitForDocumentReady = () =>
44
- new Promise((resolve, reject) => {
45
- // if the page is ready, initialize p5 immediately
46
- if (document.readyState === 'complete') {
47
- resolve();
48
- // if the page is still loading, add an event listener
49
- // and initialize p5 as soon as it finishes loading
50
- } else {
51
- window.addEventListener('load', resolve, false);
52
- }
53
- });
54
-
55
- // only load translations if we're using the full, un-minified library
56
- export const waitingForTranslator =
57
- typeof IS_MINIFIED === 'undefined' ? initTranslator() :
58
- Promise.resolve();
@@ -1,195 +0,0 @@
1
- import i18next from 'i18next';
2
- import LanguageDetector from 'i18next-browser-languagedetector';
3
- import { default as fallbackResources, languages } from '../../translations';
4
-
5
- if (typeof IS_MINIFIED === 'undefined') {
6
- // internationalization is only for the unminified build
7
-
8
- if (typeof P5_DEV_BUILD !== 'undefined') {
9
- // When the library is built in development mode ( using npm run dev )
10
- // we want to use the current translation files on the disk, which may have
11
- // been updated but not yet pushed to the CDN.
12
- let completeResources = require('../../translations/dev');
13
- for (const language of Object.keys(completeResources)) {
14
- // In es_translation, language is es and namespace is translation
15
- // In es_MX_translation, language is es-MX and namespace is translation
16
- const parts = language.split('_');
17
- const lng = parts.slice(0, parts.length - 1).join('-');
18
- const ns = parts[parts.length - 1];
19
-
20
- fallbackResources[lng] = fallbackResources[lng] || {};
21
- fallbackResources[lng][ns] = completeResources[language];
22
- }
23
- }
24
- }
25
-
26
- /*
27
- * This is our i18next "backend" plugin. It tries to fetch languages
28
- * from a CDN.
29
- * @private
30
- */
31
- class FetchResources {
32
- constructor(services, options) {
33
- this.init(services, options);
34
- }
35
-
36
- // run fetch with a timeout. Automatically rejects on timeout
37
- // default timeout = 2000 ms
38
- fetchWithTimeout(url, options, timeout = 2000) {
39
- return Promise.race([
40
- fetch(url, options),
41
- new Promise((_, reject) =>
42
- setTimeout(() => reject(new Error('timeout')), timeout)
43
- )
44
- ]);
45
- }
46
-
47
- init(services, options = {}) {
48
- this.services = services;
49
- this.options = options;
50
- }
51
-
52
- read(language, namespace, callback) {
53
- const loadPath = this.options.loadPath;
54
-
55
- if (language === this.options.fallback) {
56
- // if the default language of the user is the same as our inbuilt fallback,
57
- // there's no need to fetch resources from the cdn. This won't actually
58
- // need to run when we use "partialBundledLanguages" in the init
59
- // function.
60
- callback(null, fallbackResources[language][namespace]);
61
- } else if (languages.includes(language)) {
62
- // The user's language is included in the list of languages
63
- // that we so far added translations for.
64
-
65
- const url = this.services.interpolator.interpolate(loadPath, {
66
- lng: language,
67
- ns: namespace
68
- });
69
- this.loadUrl(url, callback);
70
- } else {
71
- // We don't have translations for this language. i18next will use
72
- // the default language instead.
73
- callback('Not found', false);
74
- }
75
- }
76
-
77
- loadUrl(url, callback) {
78
- this.fetchWithTimeout(url)
79
- .then(
80
- response => {
81
- const ok = response.ok;
82
-
83
- if (!ok) {
84
- // caught in the catch() below
85
- throw new Error(`failed loading ${url}`);
86
- }
87
- return response.json();
88
- },
89
- () => {
90
- // caught in the catch() below
91
- throw new Error(`failed loading ${url}`);
92
- }
93
- )
94
- .then(data => {
95
- return callback(null, data);
96
- })
97
- .catch(callback);
98
- }
99
- }
100
- FetchResources.type = 'backend';
101
-
102
- /**
103
- * This is our translation function. Give it a key and
104
- * it will retrieve the appropriate string
105
- * (within supported languages) according to the
106
- * user's browser's language settings.
107
- * @function translator
108
- * @param {String} key a key that corresponds to a message in our translation files
109
- * @param {Object} values values for use in the message under the given `key`
110
- * @returns {String} message (with values inserted) in the user's browser language
111
- * @private
112
- */
113
- export let translator = (key, values) => {
114
- console.debug('p5.js translator called before translations were loaded');
115
-
116
- // Certain FES functionality may trigger before translations are downloaded.
117
- // Using "partialBundledLanguages" option during initialization, we can
118
- // still use our fallback language to display messages
119
- i18next.t(key, values); /* i18next-extract-disable-line */
120
- };
121
- // (We'll set this to a real value in the init function below!)
122
-
123
- /*
124
- * Set up our translation function, with loaded languages
125
- * @private
126
- */
127
- export const initialize = () => {
128
- let i18init = i18next
129
- .use(LanguageDetector)
130
- .use(FetchResources)
131
- .init({
132
- fallbackLng: 'en',
133
- nestingPrefix: '$tr(',
134
- nestingSuffix: ')',
135
- defaultNS: 'translation',
136
- returnEmptyString: false,
137
- interpolation: {
138
- escapeValue: false
139
- },
140
- detection: {
141
- checkWhitelist: false,
142
-
143
- // prevent storing or locating language from cookie or localStorage
144
- // more info on https://github.com/processing/p5.js/issues/4862
145
- order: ['querystring', 'navigator', 'htmlTag', 'path', 'subdomain'],
146
- caches: []
147
- },
148
- backend: {
149
- fallback: 'en',
150
- loadPath:
151
- 'https://cdn.jsdelivr.net/npm/p5/translations/{{lng}}/{{ns}}.json'
152
- },
153
- partialBundledLanguages: true,
154
- resources: fallbackResources
155
- })
156
- .then(
157
- translateFn => {
158
- translator = translateFn;
159
- },
160
- e => console.debug(`Translations failed to load (${e})`)
161
- );
162
-
163
- // i18next.init() returns a promise that resolves when the translations
164
- // are loaded. We use this in core/init.js to hold p5 initialization until
165
- // we have the translation files.
166
- return i18init;
167
- };
168
-
169
- /*
170
- * Returns a list of languages we have translations loaded for
171
- * @private
172
- */
173
- export const availableTranslatorLanguages = () => {
174
- return i18next.languages;
175
- };
176
-
177
- /*
178
- * Returns the current language selected for translation
179
- * @private
180
- */
181
- export const currentTranslatorLanguage = language => {
182
- return i18next.language;
183
- };
184
-
185
- /*
186
- * Sets the current language for translation
187
- * Returns a promise that resolved when loading is finished,
188
- * or rejects if it fails.
189
- * @private
190
- */
191
- export const setTranslatorLanguage = language => {
192
- return i18next.changeLanguage(language || undefined, e =>
193
- console.debug(`Translations failed to load (${e})`)
194
- );
195
- };
@@ -1,29 +0,0 @@
1
- /**
2
- * @for p5
3
- * @requires core
4
- * These are functions that are part of the Processing API but are not part of
5
- * the p5.js API. In some cases they have a new name, in others, they are
6
- * removed completely. Not all unsupported Processing functions are listed here
7
- * but we try to include ones that a user coming from Processing might likely
8
- * call.
9
- */
10
-
11
- import p5 from './main';
12
-
13
- p5.prototype.pushStyle = function() {
14
- throw new Error('pushStyle() not used, see push()');
15
- };
16
-
17
- p5.prototype.popStyle = function() {
18
- throw new Error('popStyle() not used, see pop()');
19
- };
20
-
21
- p5.prototype.popMatrix = function() {
22
- throw new Error('popMatrix() not used, see pop()');
23
- };
24
-
25
- p5.prototype.pushMatrix = function() {
26
- throw new Error('pushMatrix() not used, see push()');
27
- };
28
-
29
- export default p5;