diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 3d8616b98f0741..3f007834778527 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1825,7 +1825,6 @@ /types/eris-sharder/ @mathletedev /types/err/ @jimmycuadra /types/error-cause/ @conartist6 @ljharb -/types/error-subclass/ @fitbit /types/errorhandler/ @santialbo @peterblazejewicz /types/es-abstract/ @ljharb @ExE-Boss /types/es-aggregate-error/ @AverageHelper @@ -3937,6 +3936,7 @@ /types/kahoot.js-updated/ @MysteryBlokHed /types/kakao-js-sdk/ @wooogi123 /types/kakao-pixel/ @hahnlee +/types/kakao.postcode/ @doinki /types/kakaomaps/ @MinByeongDon @positiveko @yongdamsh /types/kalmanjs/ @wouterbulten /types/kaluma/ @jt000 @@ -4650,6 +4650,7 @@ /types/lzbase62/ @ArthurKa /types/lzma/ @Goldsmith42 /types/lzma-native/ @leshow +/types/lzwcompress/ @floydpink /types/m3u8-parser/ @k-yle @dyc3 /types/macaca-circular-json/ @jpevarnek /types/macrotask/ @BendingBender @@ -5147,6 +5148,7 @@ /types/node/v20/ @Microsoft @jkomyno @r3nya @btoueg @touffy @mohsen1 @galkin @eps1lon @WilcoBakker @chyzwar @trivikr @yoursunny @qwelias @ExE-Boss @peterblazejewicz @addaleax @victorperin @NodeJS @LinusU @wafuwafu13 @mcollina @Semigradsky /types/node/v22/ @Microsoft @jkomyno @r3nya @btoueg @touffy @mohsen1 @galkin @eps1lon @WilcoBakker @chyzwar @trivikr @yoursunny @qwelias @ExE-Boss @peterblazejewicz @addaleax @victorperin @NodeJS @LinusU @wafuwafu13 @mcollina @Semigradsky @Renegade334 /types/node/v24/ @Microsoft @jkomyno @r3nya @btoueg @touffy @mohsen1 @galkin @eps1lon @WilcoBakker @chyzwar @trivikr @yoursunny @qwelias @ExE-Boss @peterblazejewicz @addaleax @victorperin @NodeJS @LinusU @wafuwafu13 @mcollina @Semigradsky @Renegade334 @anonrig +/types/node/v25/ @Microsoft @jkomyno @r3nya @btoueg @touffy @mohsen1 @galkin @eps1lon @WilcoBakker @chyzwar @trivikr @yoursunny @qwelias @ExE-Boss @peterblazejewicz @addaleax @victorperin @NodeJS @LinusU @wafuwafu13 @mcollina @Semigradsky @Renegade334 @anonrig /types/node-7z/ @erkie @colin969 /types/node-abi/ @ffflorian /types/node-apple-receipt-verify/ @serinuntius @@ -5762,6 +5764,7 @@ /types/polygon-selfintersect/ @mcruss /types/polygons-intersect/ @Nielio /types/polylabel/ @DenisCarriere +/types/polylabel/v1/ @DenisCarriere /types/polyline/ @Kern0 /types/polymer/ @lgrignon /types/poool-access/ @maximedasilva @dackmin @@ -7958,7 +7961,7 @@ /types/turbostatus/ @ffflorian /types/turndown/ @sergey-zhidkov /types/tusk-mastodon/ @fishcharlie -/types/tuya-panel-kit/ @youngjuning @ShinyLeee +/types/tuya-panel-kit/ @ShinyLeee /types/tv4/ @Bartvds @psnider /types/tween-functions/ @hozblok /types/tweenjs/ @evilangelist @jcyuan @@ -8387,7 +8390,7 @@ /types/websocket-async/ @bigbeno37 /types/websql/ @TeamworkGuy2 /types/webtorrent/ @niieani @tlaziuk @gjuchault @cheeseandcereal -/types/webvis/ @threedy-io @instant3Dhub @tsturm @dbthreed @ErikSpiegelberg @TimLamThreedy +/types/webvis/ @threedy-io @instant3Dhub @tsturm @dbthreed @ErikSpiegelberg @TimLamThreedy @n-fix /types/webvr-api/ @efokschaner /types/webvtt-parser/ @dodomorandi /types/webxr/ @robrohan @RaananW @capnmidnight @sorskoot @@ -8469,7 +8472,6 @@ /types/wordpress__block-serialization-spec-parser/ @dsifford /types/wordpress__customize-browser/ @marekdedic /types/wordpress__edit-post/ @dsifford -/types/wordpress__server-side-render/ @rafaucau /types/words-to-time-converter/ @peterblazejewicz /types/wordwrap/ @ark120202 /types/wordwrapjs/ @stoyan-karev diff --git a/attw.json b/attw.json index 96f289a3fb8919..e42a8c3aea9683 100644 --- a/attw.json +++ b/attw.json @@ -202,7 +202,7 @@ "passport-discord", "phoenix", "playmusic", - "polylabel", + "polylabel/v1", "postcss-functions", "postcss-js", "posterus", diff --git a/types/polylabel/.npmignore b/types/polylabel/.npmignore index 93e307400a5456..a1a47f74ce9f12 100644 --- a/types/polylabel/.npmignore +++ b/types/polylabel/.npmignore @@ -3,3 +3,4 @@ !**/*.d.cts !**/*.d.mts !**/*.d.*.ts +/v1/ diff --git a/types/polylabel/index.d.ts b/types/polylabel/index.d.ts index 19e694490291b4..462ceb56aab945 100644 --- a/types/polylabel/index.d.ts +++ b/types/polylabel/index.d.ts @@ -1,12 +1,21 @@ /** - * Polylabel returns the pole of inaccessibility coordinate in [x, y] format. + * Returns the pole of inaccessibility for a polygon — the most distant internal + * point from the polygon outline — as a `[x, y]` coordinate pair. The + * `distance` property on the returned array holds the distance from the pole to + * the nearest polygon edge (the "pole radius"). * - * @param polygon - Given polygon coordinates in GeoJSON-like format - * @param precision - Precision (1.0 by default) - * @param debug - Debugging for Console + * @param polygon - Polygon rings: outer ring first, holes (if any) following. + * Each ring is an array of `[x, y]` coordinate pairs. + * @param precision - Precision of the result in the same units as the polygon + * coordinates. Defaults to `1.0`. + * @param debug - When `true`, logs progress to the console. * @example - * var p = polylabel(polygon, 1.0); + * const [x, y] = polylabel(polygon, 1.0); */ -declare function polylabel(polygon: number[][][], precision?: number, debug?: boolean): number[] & { distance: number }; +declare function polylabel( + polygon: Array>, + precision?: number, + debug?: boolean, +): [number, number] & { distance: number }; declare namespace polylabel {} export default polylabel; diff --git a/types/polylabel/package.json b/types/polylabel/package.json index d73d3a9a2191f7..cf7a4bf85ccc6a 100644 --- a/types/polylabel/package.json +++ b/types/polylabel/package.json @@ -1,7 +1,8 @@ { "private": true, "name": "@types/polylabel", - "version": "1.1.9999", + "version": "2.0.9999", + "type": "module", "projects": [ "https://github.com/mapbox/polylabel" ], diff --git a/types/polylabel/polylabel-tests.ts b/types/polylabel/polylabel-tests.ts index 783eaddb71cd46..89983ee6104b49 100644 --- a/types/polylabel/polylabel-tests.ts +++ b/types/polylabel/polylabel-tests.ts @@ -1,18 +1,50 @@ import polylabel from "polylabel"; -const polygon = [[[3116, 3071], [3118, 3068], [3108, 3102], [3751, 927]]]; +// Simple polygon (outer ring only) +const polygon: Array> = [ + [ + [3116, 3071], + [3118, 3068], + [3108, 3102], + [3751, 927], + ], +]; + +// Polygon with a hole (outer ring + one inner ring) +const polygonWithHole: Array> = [ + [ + [0, 0], + [100, 0], + [100, 100], + [0, 100], + [0, 0], + ], + [ + [20, 20], + [20, 80], + [80, 80], + [80, 20], + [20, 20], + ], +]; + polylabel(polygon); polylabel(polygon, 1.0); polylabel(polygon, 1.0, true); polylabel(polygon, 1.0, false); +polylabel(polygonWithHole, 0.1); + +// $ExpectType [number, number] & { distance: number; } +const result = polylabel(polygon); // $ExpectType number -polylabel(polygon)[0]; +result[0]; // $ExpectType number -polylabel(polygon)[1]; +result[1]; // $ExpectType number -polylabel(polygon).distance; +result.distance; +// Tuple destructuring const [x, y] = polylabel(polygon); // $ExpectType number x; diff --git a/types/polylabel/v1/.npmignore b/types/polylabel/v1/.npmignore new file mode 100644 index 00000000000000..93e307400a5456 --- /dev/null +++ b/types/polylabel/v1/.npmignore @@ -0,0 +1,5 @@ +* +!**/*.d.ts +!**/*.d.cts +!**/*.d.mts +!**/*.d.*.ts diff --git a/types/polylabel/v1/index.d.ts b/types/polylabel/v1/index.d.ts new file mode 100644 index 00000000000000..19e694490291b4 --- /dev/null +++ b/types/polylabel/v1/index.d.ts @@ -0,0 +1,12 @@ +/** + * Polylabel returns the pole of inaccessibility coordinate in [x, y] format. + * + * @param polygon - Given polygon coordinates in GeoJSON-like format + * @param precision - Precision (1.0 by default) + * @param debug - Debugging for Console + * @example + * var p = polylabel(polygon, 1.0); + */ +declare function polylabel(polygon: number[][][], precision?: number, debug?: boolean): number[] & { distance: number }; +declare namespace polylabel {} +export default polylabel; diff --git a/types/polylabel/v1/package.json b/types/polylabel/v1/package.json new file mode 100644 index 00000000000000..d73d3a9a2191f7 --- /dev/null +++ b/types/polylabel/v1/package.json @@ -0,0 +1,17 @@ +{ + "private": true, + "name": "@types/polylabel", + "version": "1.1.9999", + "projects": [ + "https://github.com/mapbox/polylabel" + ], + "devDependencies": { + "@types/polylabel": "workspace:." + }, + "owners": [ + { + "name": "Denis Carriere", + "githubUsername": "DenisCarriere" + } + ] +} diff --git a/types/polylabel/v1/polylabel-tests.ts b/types/polylabel/v1/polylabel-tests.ts new file mode 100644 index 00000000000000..783eaddb71cd46 --- /dev/null +++ b/types/polylabel/v1/polylabel-tests.ts @@ -0,0 +1,20 @@ +import polylabel from "polylabel"; + +const polygon = [[[3116, 3071], [3118, 3068], [3108, 3102], [3751, 927]]]; +polylabel(polygon); +polylabel(polygon, 1.0); +polylabel(polygon, 1.0, true); +polylabel(polygon, 1.0, false); + +// $ExpectType number +polylabel(polygon)[0]; +// $ExpectType number +polylabel(polygon)[1]; +// $ExpectType number +polylabel(polygon).distance; + +const [x, y] = polylabel(polygon); +// $ExpectType number +x; +// $ExpectType number +y; diff --git a/types/polylabel/v1/tsconfig.json b/types/polylabel/v1/tsconfig.json new file mode 100644 index 00000000000000..452c15e5fe5505 --- /dev/null +++ b/types/polylabel/v1/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "node16", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "polylabel-tests.ts" + ] +}