diff --git a/contributor_docs/ko/method.example.js b/contributor_docs/ko/method.example.js index 72c889878b..782dd40111 100644 --- a/contributor_docs/ko/method.example.js +++ b/contributor_docs/ko/method.example.js @@ -1,5 +1,5 @@ /** - * "이것은 메소드의 인라인 문서 템플릿입니다. 이 템플릿을 사용하려면 큰 따옴표 + * "이것은 메소드의 인라인 문서 템플릿입니다. 이 템플릿을 사용하려면 큰 따옴표 * 사이의 모든 텍스트를 제거하십시오. 메소드에 대한 일부 설명은 여기에 들어갑니다. * 간단한 단어로 함수가 하는 일과 그에 대한 좋은/나쁜 사용 예를 설명하십시오. * 만약 비정상적인 케이스나 경고가 있다면 여기에서 설명해 주세요." @@ -31,7 +31,7 @@ * "두 번째 예시를 명확히 설명하는 줄입니다" */ -// "메소드에 둘 이상의 특징이 있으면, 각 특징은 다음과 같은 파라미터 설명과 함께 +// "메소드에 둘 이상의 특징이 있으면, 각 특징은 다음과 같은 파라미터 설명과 함께 // 자체 블록에 문서화할 수 있습니다." /** * @method "메소드명" @@ -46,11 +46,11 @@ p5.prototype.methodName = function() { // 이 부분은 템플릿을 채운 예시입니다. /** - * background() 함수는 p5.js 캔버스의 배경 색상을 - * 설정합니다. 이 함수는 일반적으로 draw()에서 각 프레임의 시작 부분에 디스플레이 - * 윈도우를 지우는 데 사용되지만, 애니메이션의 첫 번째 프레임에 배경색을 설정하거나 + * background() 함수는 p5.js 캔버스의 배경 색상을 + * 설정합니다. 이 함수는 일반적으로 draw()에서 각 프레임의 시작 부분에 디스플레이 + * 윈도우를 지우는 데 사용되지만, 애니메이션의 첫 번째 프레임에 배경색을 설정하거나 * 배경을 한 번만 설정해야 할 경우 setup() 내에서 사용할 수 있습니다. - * + * * 배경색 기본 설정은 투명입니다. * * @method background @@ -81,7 +81,7 @@ p5.prototype.methodName = function() { /** * @method background * @param {String} 문자열 형태의 색상 설정에 사용할 수 있는 형식: - 정수, rgb(), rgba(), rgb() 비율, rgba() 비율, + 정수, rgb(), rgba(), rgb() 비율, rgba() 비율, 3자리 16진법, 6자리 16진법, * @param {Number} [a] * @chainable diff --git a/contributor_docs/project_wrapups/slominski_gsoc_2022.md b/contributor_docs/project_wrapups/slominski_gsoc_2022.md index 4d00fc32e2..195f347136 100644 --- a/contributor_docs/project_wrapups/slominski_gsoc_2022.md +++ b/contributor_docs/project_wrapups/slominski_gsoc_2022.md @@ -47,6 +47,6 @@ The tutorials can be found on the p5.js websites Learn section here (to be added And the code and commits for these contributions can be found at (to be added): -##Acknowledgements +## Acknowledgements I want to express my gratitude towards my mentor Kate Hollenbach for her guidance throughout this project, as well as towards the p5.js community for its openness and helpfulness. diff --git a/docs/parameterData.json b/docs/parameterData.json index 3fc79dbeed..8b767d876b 100644 --- a/docs/parameterData.json +++ b/docs/parameterData.json @@ -4655,6 +4655,10 @@ }, "modify": { "overloads": [ + [ + "Function", + "Object?" + ], [ "Object?" ] diff --git a/eslint.config.mjs b/eslint.config.mjs index 040c2b7727..a691ea6ea0 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -80,7 +80,7 @@ const commonRules = { '@stylistic/max-len': [ warn, { - code: 80, + code: 120, ignoreComments: true, ignoreStrings: true, ignoreTemplateLiterals: true, @@ -272,4 +272,4 @@ export default defineConfig([ // * contributor_docs/zh-Hans/unit_testing.md 35:1 error Parsing error: Unexpected token // * rfc_p5js_2.md 205:50 error Parsing error: Binding arguments in strict mode // ...markdown.configs.processor -]); \ No newline at end of file +]); diff --git a/package.json b/package.json index c18ed30084..0e7ca1c1ab 100644 --- a/package.json +++ b/package.json @@ -69,20 +69,62 @@ "license": "LGPL-2.1", "browser": "./lib/p5.min.js", "exports": { - ".": "./dist/app.js", - "./core": "./dist/core/main.js", - "./shape": "./dist/shape/index.js", - "./accessibility": "./dist/accessibility/index.js", - "./friendlyErrors": "./dist/core/friendlyErrors/index.js", - "./data": "./dist/data/index.js", - "./dom": "./dist/dom/index.js", - "./events": "./dist/events/index.js", - "./image": "./dist/image/index.js", - "./io": "./dist/io/index.js", - "./math": "./dist/math/index.js", - "./utilities": "./dist/utilities/index.js", - "./webgl": "./dist/webgl/index.js", - "./type": "./dist/type/index.js" + ".": { + "default": "./dist/app.js", + "types": "./types/p5.d.ts" + }, + "./core": { + "default": "./dist/core/main.js", + "types": "./types/core/main.d.ts" + }, + "./shape": { + "default": "./dist/shape/index.js", + "types": "./types/shape/index.d.ts" + }, + "./accessibility": { + "default": "./dist/accessibility/index.js", + "types": "./types/accessibility/index.d.ts" + }, + "./friendly_errors": { + "default": "./dist/core/friendly_errors/index.js", + "types": "./types/core/friendly_errors/index.d.ts" + }, + "./data": { + "default": "./dist/data/index.js", + "types": "./types/data/index.d.ts" + }, + "./dom": { + "default": "./dist/dom/index.js", + "types": "./types/dom/index.d.ts" + }, + "./events": { + "default": "./dist/events/index.js", + "types": "./types/events/index.d.ts" + }, + "./image": { + "default": "./dist/image/index.js", + "types": "./types/image/index.d.ts" + }, + "./io": { + "default": "./dist/io/index.js", + "types": "./types/io/index.d.ts" + }, + "./math": { + "default": "./dist/math/index.js", + "types": "./types/math/index.d.ts" + }, + "./utilities": { + "default": "./dist/utilities/index.js", + "types": "./types/utilities/index.d.ts" + }, + "./webgl": { + "default": "./dist/webgl/index.js", + "types": "./types/webgl/index.d.ts" + }, + "./type": { + "default": "./dist/type/index.js", + "types": "./types/type/index.d.ts" + } }, "files": [ "dist/**", @@ -111,6 +153,5 @@ "workerDirectory": [ "test" ] - }, - "types": "./types/p5.d.ts" + } } diff --git a/src/color/p5.Color.js b/src/color/p5.Color.js index 8e2a9d8e82..a3dc0be40b 100644 --- a/src/color/p5.Color.js +++ b/src/color/p5.Color.js @@ -37,7 +37,7 @@ const map = (n, start1, stop1, start2, stop2, clamp) => { result = Math.min(result, Math.max(start2, stop2)); } return result; -} +}; const serializationMap = {}; @@ -547,11 +547,11 @@ class Color { let coords = structuredClone(to(this._color, 'srgb').coords); coords.push(this._color.alpha); - const rangeMaxes = maxes.map((v) => { + const rangeMaxes = maxes.map(v => { if(!Array.isArray(v)){ return [0, v]; }else{ - return v + return v; } }); diff --git a/src/core/friendly_errors/sketch_verifier.js b/src/core/friendly_errors/sketch_verifier.js index b8f6e70db6..c56c84b6de 100644 --- a/src/core/friendly_errors/sketch_verifier.js +++ b/src/core/friendly_errors/sketch_verifier.js @@ -24,7 +24,7 @@ const ignoreFunction = [ 'keyPressed', 'keyReleased', 'keyTyped', - 'windowResized', + 'windowResized' // 'name', // 'parent', // 'toString', diff --git a/src/image/filterRenderer2D.js b/src/image/filterRenderer2D.js index cd0a97fe0a..af3edbd1cc 100644 --- a/src/image/filterRenderer2D.js +++ b/src/image/filterRenderer2D.js @@ -257,9 +257,9 @@ class FilterRenderer2D { const identityMatrix = [1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1]; + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1]; this._shader.setUniform('uModelViewMatrix', identityMatrix); this._shader.setUniform('uProjectionMatrix', identityMatrix); diff --git a/src/shape/curves.js b/src/shape/curves.js index b83a9dbfe0..d8c1c4a3a2 100644 --- a/src/shape/curves.js +++ b/src/shape/curves.js @@ -517,22 +517,22 @@ function curves(p5, fn){ * function setup() { * createCanvas(200, 200); * background(245); - * + * * // Ensure the curve includes both end spans p0->p1 and p2->p3 * splineProperty('ends', INCLUDE); - * + * * // Control / anchor points * const p0 = createVector(30, 160); * const p1 = createVector(60, 40); * const p2 = createVector(140, 40); * const p3 = createVector(170, 160); - * + * * // Draw the spline that passes through ALL four points (INCLUDE) * noFill(); * stroke(0); * strokeWeight(2); * spline(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); - * + * * // Draw markers + labels * fill(255); * stroke(0); @@ -541,19 +541,19 @@ function curves(p5, fn){ * circle(p1.x, p1.y, r); * circle(p2.x, p2.y, r); * circle(p3.x, p3.y, r); - * + * * noStroke(); * fill(0); * text('p0', p0.x - 14, p0.y + 14); * text('p1', p1.x - 14, p1.y - 8); * text('p2', p2.x + 4, p2.y - 8); * text('p3', p3.x + 4, p3.y + 14); - * + * * describe('A black Catmull-Rom spline passes through p0, p1, p2, p3 with endpoints included.'); * } * * - * + * *
* * function setup() { @@ -848,45 +848,45 @@ function curves(p5, fn){ * } * *
- * + * *
* * let p0, p1, p2, p3; - * + * * function setup() { * createCanvas(200, 200); * splineProperty('ends', INCLUDE); // make endpoints part of the curve - * + * * // Four points forming a gentle arch * p0 = createVector(30, 160); * p1 = createVector(60, 50); * p2 = createVector(140, 50); * p3 = createVector(170, 160); - * + * * describe('Black spline through p0–p3. A red dot marks the location at parameter t on p1->p2 using splinePoint.'); * } - * + * * function draw() { * background(245); - * + * * // Draw the spline for context * noFill(); * stroke(0); * strokeWeight(2); * spline(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); - * + * * // Map mouse X to t in [0, 1] (span p1->p2) * let t = constrain(map(mouseX, 0, width, 0, 1), 0, 1); - * + * * // Evaluate the curve point by axis (splinePoint works one axis at a time) * let x = splinePoint(p0.x, p1.x, p2.x, p3.x, t); * let y = splinePoint(p0.y, p1.y, p2.y, p3.y, t); - * + * * // Marker at the evaluated position * noStroke(); * fill('red'); * circle(x, y, 8); - * + * * // Draw control/anchor points * stroke(0); * strokeWeight(1); @@ -896,7 +896,7 @@ function curves(p5, fn){ * circle(p1.x, p1.y, r); * circle(p2.x, p2.y, r); * circle(p3.x, p3.y, r); - * + * * // Labels + UI hint * noStroke(); * fill(20); @@ -909,7 +909,7 @@ function curves(p5, fn){ * } * *
- * + * */ fn.splinePoint = function(a, b, c, d, t) { diff --git a/src/shape/custom_shapes.js b/src/shape/custom_shapes.js index f9b2da245d..076c7987cb 100644 --- a/src/shape/custom_shapes.js +++ b/src/shape/custom_shapes.js @@ -1823,7 +1823,7 @@ function customShapes(p5, fn) { * } * * - * + * * @example *
* @@ -1833,44 +1833,44 @@ function customShapes(p5, fn) { * let vertexD; * let vertexE; * let vertexF; - * + * * let markerRadius; - * + * * let vectorAB; * let vectorFE; - * + * * let endOfTangentB; * let endOfTangentE; - * + * * function setup() { * createCanvas(100, 100); - * + * * // Initialize variables * // Adjusting vertices A and F affects the slopes at B and E - * + * * vertexA = createVector(35, 85); * vertexB = createVector(25, 70); * vertexC = createVector(30, 30); * vertexD = createVector(70, 30); * vertexE = createVector(75, 70); * vertexF = createVector(65, 85); - * + * * markerRadius = 4; - * + * * vectorAB = p5.Vector.sub(vertexB, vertexA); * vectorFE = p5.Vector.sub(vertexE, vertexF); - * + * * endOfTangentB = p5.Vector.add(vertexC, vectorAB); * endOfTangentE = p5.Vector.add(vertexD, vectorFE); - * + * * splineProperty(`ends`, EXCLUDE); - * + * * // Draw figure - * + * * background(220); - * + * * noFill(); - * + * * beginShape(); * splineVertex(vertexA.x, vertexA.y); * splineVertex(vertexB.x, vertexB.y); @@ -1879,15 +1879,15 @@ function customShapes(p5, fn) { * splineVertex(vertexE.x, vertexE.y); * splineVertex(vertexF.x, vertexF.y); * endShape(); - * + * * stroke('red'); * line(vertexA.x, vertexA.y, vertexC.x, vertexC.y); * line(vertexB.x, vertexB.y, endOfTangentB.x, endOfTangentB.y); - * + * * stroke('blue'); * line(vertexD.x, vertexD.y, vertexF.x, vertexF.y); * line(vertexE.x, vertexE.y, endOfTangentE.x, endOfTangentE.y); - * + * * fill('white'); * stroke('black'); * circle(vertexA.x, vertexA.y, markerRadius); @@ -1896,7 +1896,7 @@ function customShapes(p5, fn) { * circle(vertexD.x, vertexD.y, markerRadius); * circle(vertexE.x, vertexE.y, markerRadius); * circle(vertexF.x, vertexF.y, markerRadius); - * + * * fill('black'); * noStroke(); * text('A', vertexA.x - 15, vertexA.y + 5); @@ -1905,7 +1905,7 @@ function customShapes(p5, fn) { * text('D', vertexD.x - 5, vertexD.y - 5); * text('E', vertexE.x + 5, vertexE.y + 5); * text('F', vertexF.x + 5, vertexF.y + 5); - * + * * describe('On a gray background, a black spline passes through vertices A, B, C, D, E, and F, shown as white circles. A red line segment joining vertices A and C has the same slope as the red tangent segment at B. Similarly, the blue line segment joining vertices D and F has the same slope as the blue tangent at E.'); * } * @@ -2069,7 +2069,7 @@ function customShapes(p5, fn) { * spline(25, 46, 93, 44, 93, 81, 35, 85); * ``` * - * + * * In all cases, the splines in p5.js are cardinal splines. * When tightness is 0, these splines are often known as * Catmull-Rom splines @@ -2185,9 +2185,9 @@ function customShapes(p5, fn) { * } * *
- * + * * @example - * + * *
* * let vertexA; @@ -2196,44 +2196,44 @@ function customShapes(p5, fn) { * let vertexD; * let vertexE; * let vertexF; - * + * * let markerRadius; - * + * * let vectorAB; * let vectorFE; - * + * * let endOfTangentB; * let endOfTangentE; - * + * * function setup() { * createCanvas(100, 100); - * + * * // Initialize variables * // Adjusting vertices A and F affects the slopes at B and E - * + * * vertexA = createVector(35, 85); * vertexB = createVector(25, 70); * vertexC = createVector(30, 30); * vertexD = createVector(70, 30); * vertexE = createVector(75, 70); * vertexF = createVector(65, 85); - * + * * markerRadius = 4; - * + * * vectorAB = p5.Vector.sub(vertexB, vertexA); * vectorFE = p5.Vector.sub(vertexE, vertexF); - * + * * endOfTangentB = p5.Vector.add(vertexC, vectorAB); * endOfTangentE = p5.Vector.add(vertexD, vectorFE); - * + * * splineProperty(`ends`, EXCLUDE); - * + * * // Draw figure - * + * * background(220); - * + * * noFill(); - * + * * beginShape(); * splineVertex(vertexA.x, vertexA.y); * splineVertex(vertexB.x, vertexB.y); @@ -2242,15 +2242,15 @@ function customShapes(p5, fn) { * splineVertex(vertexE.x, vertexE.y); * splineVertex(vertexF.x, vertexF.y); * endShape(); - * + * * stroke('red'); * line(vertexA.x, vertexA.y, vertexC.x, vertexC.y); * line(vertexB.x, vertexB.y, endOfTangentB.x, endOfTangentB.y); - * + * * stroke('blue'); * line(vertexD.x, vertexD.y, vertexF.x, vertexF.y); * line(vertexE.x, vertexE.y, endOfTangentE.x, endOfTangentE.y); - * + * * fill('white'); * stroke('black'); * circle(vertexA.x, vertexA.y, markerRadius); @@ -2259,7 +2259,7 @@ function customShapes(p5, fn) { * circle(vertexD.x, vertexD.y, markerRadius); * circle(vertexE.x, vertexE.y, markerRadius); * circle(vertexF.x, vertexF.y, markerRadius); - * + * * fill('black'); * noStroke(); * text('A', vertexA.x - 15, vertexA.y + 5); @@ -2268,12 +2268,12 @@ function customShapes(p5, fn) { * text('D', vertexD.x - 5, vertexD.y - 5); * text('E', vertexE.x + 5, vertexE.y + 5); * text('F', vertexF.x + 5, vertexF.y + 5); - * + * * describe('On a gray background, a black spline passes through vertices A, B, C, D, E, and F, shown as white circles. A red line segment joining vertices A and C has the same slope as the red tangent segment at B. Similarly, the blue line segment joining vertices D and F has the same slope as the blue tangent at E.'); * } * *
- * + * */ /** diff --git a/src/type/textCore.js b/src/type/textCore.js index 5e0efbe8fe..203642a846 100644 --- a/src/type/textCore.js +++ b/src/type/textCore.js @@ -755,7 +755,7 @@ function textCore(p5, fn) { * * For example, if the text contains multiple lines due to wrapping or explicit line breaks, textWidth() * will return the width of the longest line. - * + * * **Note:** In p5.js 2.0+, leading and trailing spaces are ignored. * `textWidth(" Hello ")` returns the same width as `textWidth("Hello")`. * diff --git a/src/webgl/ShaderGenerator.js b/src/webgl/ShaderGenerator.js index 2e716ce39f..a15bd4c597 100644 --- a/src/webgl/ShaderGenerator.js +++ b/src/webgl/ShaderGenerator.js @@ -1,9 +1,9 @@ /** -* @module 3D -* @submodule Material -* @for p5 -* @requires core -*/ + * @module 3D + * @submodule Material + * @for p5 + * @requires core + */ import { parse } from 'acorn'; import { ancestor } from 'acorn-walk'; import escodegen from 'escodegen'; @@ -1759,13 +1759,13 @@ if (typeof p5 !== 'undefined') { * @method getWorldInputs * @description * Registers a callback to modify the world-space properties of each vertex in a shader. This hook can be used inside baseColorShader().modify() and similar shader modify() calls to customize vertex positions, normals, texture coordinates, and colors before rendering. "World space" refers to the coordinate system of the 3D scene, before any camera or projection transformations are applied. - * + * * The callback receives a vertex object with the following properties: * - `position`: a three-component vector representing the original position of the vertex. * - `normal`: a three-component vector representing the direction the surface is facing. * - `texCoord`: a two-component vector representing the texture coordinates. * - `color`: a four-component vector representing the color of the vertex (red, green, blue, alpha). - * + * * This hook is available in: * - baseMaterialShader() * - baseNormalShader() @@ -1786,7 +1786,7 @@ if (typeof p5 !== 'undefined') { * getWorldInputs(inputs => { * // Move the vertex up and down in a wave in world space * // In world space, moving the object (e.g., with translate()) will affect these coordinates -* // The sphere is ~50 units tall here, so 20 gives a noticeable wave + * // The sphere is ~50 units tall here, so 20 gives a noticeable wave * inputs.position.y += 20 * sin(t * 0.001 + inputs.position.x * 0.05); * return inputs; * }); @@ -2166,7 +2166,7 @@ if (typeof p5 !== 'undefined') { * @method getObjectInputs * @description * Registers a callback to modify the properties of each vertex before any transformations are applied in the vertex shader. This hook can be used inside baseColorShader().modify() and similar shader modify() calls to move, color, or otherwise modify the raw model data. The callback receives an object with the following properties: - * + * * - `position`: a three-component vector representing the original position of the vertex. * - `normal`: a three-component vector representing the direction the surface is facing. * - `texCoord`: a two-component vector representing the texture coordinates. @@ -2213,7 +2213,7 @@ if (typeof p5 !== 'undefined') { * @method getCameraInputs * @description * Registers a callback to adjust vertex properties after the model has been transformed by the camera, but before projection, in the vertex shader. This hook can be used inside baseColorShader().modify() and similar shader modify() calls to create effects that depend on the camera's view. The callback receives an object with the following properties: - * + * * - `position`: a three-component vector representing the position after camera transformation. * - `normal`: a three-component vector representing the normal after camera transformation. * - `texCoord`: a two-component vector representing the texture coordinates. diff --git a/test/unit/assets/array.js b/test/unit/assets/array.js index 9e3ff56f24..54a39fa812 100644 --- a/test/unit/assets/array.js +++ b/test/unit/assets/array.js @@ -1,4 +1,4 @@ -// eslint-disable-next-line no-undef + jsonpCallbackFunction([ { id: 0, diff --git a/test/unit/assets/object.js b/test/unit/assets/object.js index 25738a7a5c..84f31fc172 100644 --- a/test/unit/assets/object.js +++ b/test/unit/assets/object.js @@ -1,4 +1,4 @@ -// eslint-disable-next-line no-undef + jsonpCallbackFunction({ id: 0, species: 'Panthera leo', diff --git a/utils/convert.mjs b/utils/convert.mjs index ba56c59df0..d486599cef 100644 --- a/utils/convert.mjs +++ b/utils/convert.mjs @@ -521,13 +521,6 @@ function cleanUpClassItems(data) { const flattenOverloads = funcObj => { const result = {}; - const processOverload = overload => { - if (overload.params) { - return Object.values(overload.params).map(param => processParam(param)); - } - return overload; - }; - // To simplify `parameterData.json`, instead of having a separate field for // optional parameters, we'll add a ? to the end of parameter type to // indicate that it's optional. @@ -542,6 +535,13 @@ function cleanUpClassItems(data) { return type; }; + const processOverload = overload => { + if (overload.params) { + return Object.values(overload.params).map(param => processParam(param)); + } + return overload; + }; + // In some cases, even when the arguments are intended to mean different // things, their types and order are identical. Since the exact meaning // of the arguments is less important for parameter validation, we'll diff --git a/utils/generate-types.mjs b/utils/generate-types.mjs index 5c5c05a7f1..d7024e4d3e 100644 --- a/utils/generate-types.mjs +++ b/utils/generate-types.mjs @@ -10,6 +10,7 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const data = JSON.parse(fs.readFileSync(path.join(__dirname, '../docs/data.json'))); +const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'))); function findDtsFiles(dir, files = []) { // Only search in src directory @@ -79,6 +80,34 @@ export function generateAllDeclarationFiles() { fs.writeFileSync(path.join(typesDir, 'p5.d.ts'), p5Types, 'utf8'); fs.writeFileSync(path.join(typesDir, 'global.d.ts'), globalTypes, 'utf8'); + + // Create `index.d.ts` for every sub-module directory + /** @type { Record } */ + const subModuleDefinitions = {}; + for (const entrypoint of Object.values(packageJson.exports)) { + if (entrypoint === '.') continue; + const subModuleName = entrypoint.default.replace('./dist', '').replace(/\/index\.js$/, ''); + subModuleDefinitions[subModuleName] = '// This file is auto-generated from JSDoc documentation\n\n'; + } + + for (const file of dtsFiles) { + for (const subModuleName of Object.keys(subModuleDefinitions)) { + if (file.startsWith(subModuleName + '/') && file !== subModuleName + '/index.d.ts') { + subModuleDefinitions[subModuleName] += `/// \n`; + } + } + } + + for (const [subModuleName, content] of Object.entries(subModuleDefinitions)) { + const subModuleDir = path.join(typesDir, subModuleName); + const destPath = path.join( + path.relative(process.cwd(), subModuleDir), + 'index.d.ts' + ); + fs.mkdirSync(subModuleDir, { recursive: true }); + fs.writeFileSync(destPath, content, 'utf8'); + console.log(`Generated ${destPath}`); + } } generateAllDeclarationFiles(); diff --git a/utils/helper.mjs b/utils/helper.mjs index 5506363692..91517591ce 100644 --- a/utils/helper.mjs +++ b/utils/helper.mjs @@ -18,7 +18,6 @@ export function normalizeClassName(className) { } export function generateTypeDefinitions(data) { - const organized = organizeData(data); return { @@ -244,7 +243,7 @@ function generateDeclarationFile(items, organizedData) { output += generateFunctionDeclaration(item); break; case 'constant': - case 'typedef': + case 'typedef': { const constData = organizedData.consts[item.name]; if (constData) { if (constData.description) { @@ -257,6 +256,7 @@ function generateDeclarationFile(items, organizedData) { } } break; + } } } }); @@ -278,7 +278,7 @@ export function organizeData(data) { const { module, submodule, forEntry } = getModuleInfo(entry); const className = normalizeClassName(forEntry || entry.memberof || 'p5'); - switch(entry.kind) { + switch (entry.kind) { case 'class': organized.classes[className] = { name: entry.name, @@ -293,7 +293,7 @@ export function organizeData(data) { extends: entry.tags?.find(tag => tag.title === 'extends')?.name || null }; break; case 'function': - case 'property': + case 'property': { const overloads = entry.overloads?.map(overload => ({ params: overload.params, returns: overload.returns, @@ -315,7 +315,9 @@ export function organizeData(data) { class: className, isStatic: entry.path?.[0]?.scope === 'static', overloads - }); break; + }); + break; + } case 'constant': case 'typedef': organized.consts[entry.name] = { @@ -326,7 +328,8 @@ export function organizeData(data) { module, submodule, class: forEntry || 'p5' - }; break; + }; + break; } }); return organized; @@ -373,11 +376,12 @@ export function generateTypeFromTag(param) { .join(', '); return `${baseType}<${typeParams}>`; } - case 'UnionType': + case 'UnionType': { const unionTypes = param.type.elements .map(el => generateTypeFromTag({ type: el })) .join(' | '); return unionTypes; + } case 'OptionalType': return generateTypeFromTag({ type: param.type.expression }); case 'AllLiteral': @@ -441,7 +445,6 @@ export function generateParamDeclaration(param) { } export function generateFunctionDeclaration(funcDoc) { - let output = ''; if (funcDoc.description || funcDoc.tags?.length > 0) { diff --git a/utils/patch.mjs b/utils/patch.mjs index 9aeee1b6d0..e90d81d097 100644 --- a/utils/patch.mjs +++ b/utils/patch.mjs @@ -21,14 +21,14 @@ replace( './types/webgl/p5.Geometry.d.ts', 'constructor(detailX?: number, detailY?: number, callback?: function);', `constructor( - detailX?: number, - detailY?: number, - callback?: (this: { - detailY: number, - detailX: number, - vertices: p5.Vector[], - uvs: number[] - }) => void);` + detailX?: number, + detailY?: number, + callback?: (this: { + detailY: number, + detailX: number, + vertices: p5.Vector[], + uvs: number[] + }) => void);` ); // https://github.com/p5-types/p5.ts/issues/31 @@ -37,5 +37,3 @@ replace( 'function random(choices: Array): any;', 'function random(choices: T[]): T;' ); - - diff --git a/utils/sample-linter.mjs b/utils/sample-linter.mjs index 08b4fb94e1..8ce8aec42f 100644 --- a/utils/sample-linter.mjs +++ b/utils/sample-linter.mjs @@ -101,7 +101,7 @@ const plugin = { return globalSamples.map(s => s.code + userFunctionTrailer); }, - postprocess: function(sampleMessages, filename) { + postprocess: function(sampleMessages, _filename) { const problems = []; for (let i = 0; i < sampleMessages.length; i++) {