@league-of-foundry-developers/foundry-vtt-types 12.331.3-beta → 12.331.4-beta

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 (559) hide show
  1. package/README.md +17 -18
  2. package/package.json +74 -32
  3. package/src/configuration/configuration.d.mts +316 -0
  4. package/src/configuration/documents.d.mts +295 -0
  5. package/src/configuration/globals.d.mts +357 -0
  6. package/src/configuration/index.d.mts +5 -0
  7. package/src/foundry/client/apps/app.d.mts +129 -122
  8. package/src/foundry/client/apps/av/av-config.d.mts +12 -7
  9. package/src/foundry/client/apps/av/cameras.d.mts +12 -7
  10. package/src/foundry/client/apps/dice/dice-config.d.mts +59 -0
  11. package/src/foundry/client/apps/dice/index.d.mts +1 -0
  12. package/src/foundry/client/apps/form.d.mts +114 -86
  13. package/src/foundry/client/apps/forms/actor.d.mts +21 -11
  14. package/src/foundry/client/apps/forms/adventure-exporter.d.mts +12 -7
  15. package/src/foundry/client/apps/forms/adventure-importer.d.mts +14 -6
  16. package/src/foundry/client/apps/forms/base-sheet.d.mts +16 -8
  17. package/src/foundry/client/apps/forms/card-config.d.mts +16 -8
  18. package/src/foundry/client/apps/forms/cards-config.d.mts +15 -14
  19. package/src/foundry/client/apps/forms/combat-config.d.mts +7 -7
  20. package/src/foundry/client/apps/forms/combatant-config.d.mts +3 -3
  21. package/src/foundry/client/apps/forms/default-sheets-config.d.mts +1 -1
  22. package/src/foundry/client/apps/forms/effect-config.d.mts +7 -7
  23. package/src/foundry/client/apps/forms/folder-config.d.mts +5 -5
  24. package/src/foundry/client/apps/forms/fonts.d.mts +42 -35
  25. package/src/foundry/client/apps/forms/grid-config.d.mts +12 -13
  26. package/src/foundry/client/apps/forms/image-popout.d.mts +29 -23
  27. package/src/foundry/client/apps/forms/item.d.mts +9 -9
  28. package/src/foundry/client/apps/forms/journal-page-sheet.d.mts +16 -14
  29. package/src/foundry/client/apps/forms/journal-sheet.d.mts +48 -38
  30. package/src/foundry/client/apps/forms/macro-config.d.mts +7 -7
  31. package/src/foundry/client/apps/forms/measure-template.d.mts +10 -12
  32. package/src/foundry/client/apps/forms/ownership.d.mts +5 -5
  33. package/src/foundry/client/apps/forms/playlist-config.d.mts +8 -10
  34. package/src/foundry/client/apps/forms/playlist-sound-config.d.mts +7 -7
  35. package/src/foundry/client/apps/forms/roll-table-config.d.mts +11 -10
  36. package/src/foundry/client/apps/forms/scene-config.d.mts +40 -41
  37. package/src/foundry/client/apps/forms/sheet-config.d.mts +9 -21
  38. package/src/foundry/client/apps/forms/user-config.d.mts +13 -12
  39. package/src/foundry/client/apps/hud/chatbubble.d.mts +18 -6
  40. package/src/foundry/client/apps/hud/container.d.mts +4 -4
  41. package/src/foundry/client/apps/hud/controls.d.mts +126 -81
  42. package/src/foundry/client/apps/hud/hotbar.d.mts +17 -12
  43. package/src/foundry/client/apps/hud/hud.d.mts +5 -5
  44. package/src/foundry/client/apps/hud/menu.d.mts +10 -3
  45. package/src/foundry/client/apps/hud/navigation.d.mts +14 -9
  46. package/src/foundry/client/apps/hud/pause.d.mts +9 -4
  47. package/src/foundry/client/apps/hud/players.d.mts +14 -9
  48. package/src/foundry/client/apps/i18n.d.mts +31 -27
  49. package/src/foundry/client/apps/index.d.mts +1 -0
  50. package/src/foundry/client/apps/placeables/drawing-config.d.mts +41 -33
  51. package/src/foundry/client/apps/placeables/drawing-hud.d.mts +5 -5
  52. package/src/foundry/client/apps/placeables/index.d.mts +0 -2
  53. package/src/foundry/client/apps/placeables/note-config.d.mts +28 -18
  54. package/src/foundry/client/apps/placeables/tile-config.d.mts +23 -10
  55. package/src/foundry/client/apps/placeables/tile-hud.d.mts +10 -5
  56. package/src/foundry/client/apps/placeables/token-config.d.mts +91 -58
  57. package/src/foundry/client/apps/placeables/token-hud.d.mts +12 -7
  58. package/src/foundry/client/apps/placeables/wall-config.d.mts +21 -17
  59. package/src/foundry/client/apps/sidebar/apps/chat-popout.d.mts +5 -5
  60. package/src/foundry/client/apps/sidebar/apps/client-settings.d.mts +3 -3
  61. package/src/foundry/client/apps/sidebar/apps/compendium.d.mts +15 -13
  62. package/src/foundry/client/apps/sidebar/apps/invitation-links.d.mts +3 -3
  63. package/src/foundry/client/apps/sidebar/apps/keybindings-config.d.mts +3 -2
  64. package/src/foundry/client/apps/sidebar/apps/module-management.d.mts +6 -6
  65. package/src/foundry/client/apps/sidebar/apps/permission-config.d.mts +6 -6
  66. package/src/foundry/client/apps/sidebar/apps/support-details.d.mts +34 -29
  67. package/src/foundry/client/apps/sidebar/apps/tours-management.d.mts +2 -2
  68. package/src/foundry/client/apps/sidebar/apps/world-config.d.mts +13 -10
  69. package/src/foundry/client/apps/sidebar/directory-tab-mixin.d.mts +50 -35
  70. package/src/foundry/client/apps/sidebar/document-directory.d.mts +52 -38
  71. package/src/foundry/client/apps/sidebar/package-configuration.d.mts +4 -4
  72. package/src/foundry/client/apps/sidebar/sidebar-tab.d.mts +3 -3
  73. package/src/foundry/client/apps/sidebar/sidebar.d.mts +9 -4
  74. package/src/foundry/client/apps/sidebar/tabs/actors-directory.d.mts +11 -2
  75. package/src/foundry/client/apps/sidebar/tabs/cards-directory.d.mts +11 -2
  76. package/src/foundry/client/apps/sidebar/tabs/chat-log.d.mts +39 -27
  77. package/src/foundry/client/apps/sidebar/tabs/combat-tracker.d.mts +21 -12
  78. package/src/foundry/client/apps/sidebar/tabs/compendium-directory.d.mts +30 -15
  79. package/src/foundry/client/apps/sidebar/tabs/items-directory.d.mts +11 -2
  80. package/src/foundry/client/apps/sidebar/tabs/journal-directory.d.mts +11 -2
  81. package/src/foundry/client/apps/sidebar/tabs/macros-directory.d.mts +14 -5
  82. package/src/foundry/client/apps/sidebar/tabs/playlists-directory.d.mts +30 -22
  83. package/src/foundry/client/apps/sidebar/tabs/roll-table-directory.d.mts +11 -2
  84. package/src/foundry/client/apps/sidebar/tabs/scenes-directory.d.mts +14 -5
  85. package/src/foundry/client/apps/sidebar/tabs/settings.d.mts +23 -5
  86. package/src/foundry/client/apps/templates.d.mts +1 -1
  87. package/src/foundry/client/av/client.d.mts +1 -1
  88. package/src/foundry/client/av/clients/simplepeer.d.mts +11 -1
  89. package/src/foundry/client/av/master.d.mts +2 -2
  90. package/src/foundry/client/av/settings.d.mts +17 -15
  91. package/src/foundry/client/config.d.mts +444 -312
  92. package/src/foundry/client/core/document-index.d.mts +11 -3
  93. package/src/foundry/client/core/hooks.d.mts +2 -4
  94. package/src/foundry/client/core/image.d.mts +14 -13
  95. package/src/foundry/client/core/issues.d.mts +9 -4
  96. package/src/foundry/client/core/keybindings.d.mts +5 -5
  97. package/src/foundry/client/core/nue.d.mts +1 -1
  98. package/src/foundry/client/core/packages.d.mts +397 -61
  99. package/src/foundry/client/core/settings.d.mts +62 -38
  100. package/src/foundry/client/core/socket.d.mts +2 -2
  101. package/src/foundry/client/core/sorting.d.mts +6 -6
  102. package/src/foundry/client/core/time.d.mts +6 -3
  103. package/src/foundry/client/core/tooltip.d.mts +2 -2
  104. package/src/foundry/client/core/tour.d.mts +59 -50
  105. package/src/foundry/client/core/tours.d.mts +1 -1
  106. package/src/foundry/client/core/utils.d.mts +33 -10
  107. package/src/foundry/client/core/video.d.mts +1 -1
  108. package/src/foundry/client/core/workers.d.mts +24 -17
  109. package/src/foundry/client/data/abstract/canvas-document.d.mts +21 -16
  110. package/src/foundry/client/data/abstract/client-document.d.mts +153 -183
  111. package/src/foundry/client/data/abstract/directory-collection-mixin.d.mts +23 -39
  112. package/src/foundry/client/data/abstract/document-collection.d.mts +96 -68
  113. package/src/foundry/client/data/abstract/world-collection.d.mts +47 -55
  114. package/src/foundry/client/data/collections/actors.d.mts +30 -28
  115. package/src/foundry/client/data/collections/cards.d.mts +16 -3
  116. package/src/foundry/client/data/collections/combats.d.mts +18 -5
  117. package/src/foundry/client/data/collections/compendium-collection.d.mts +81 -99
  118. package/src/foundry/client/data/collections/compendium-folders.d.mts +6 -6
  119. package/src/foundry/client/data/collections/compendium-packs.d.mts +5 -5
  120. package/src/foundry/client/data/collections/fog.d.mts +16 -3
  121. package/src/foundry/client/data/collections/folder.d.mts +20 -6
  122. package/src/foundry/client/data/collections/items.d.mts +17 -4
  123. package/src/foundry/client/data/collections/journal.d.mts +22 -7
  124. package/src/foundry/client/data/collections/macros.d.mts +21 -19
  125. package/src/foundry/client/data/collections/messages.d.mts +19 -6
  126. package/src/foundry/client/data/collections/playlists.d.mts +17 -5
  127. package/src/foundry/client/data/collections/scenes.d.mts +24 -27
  128. package/src/foundry/client/data/collections/settings.d.mts +16 -3
  129. package/src/foundry/client/data/collections/tables.d.mts +18 -5
  130. package/src/foundry/client/data/collections/users.d.mts +19 -7
  131. package/src/foundry/client/data/documents/active-effect.d.mts +677 -85
  132. package/src/foundry/client/data/documents/actor-delta.d.mts +670 -27
  133. package/src/foundry/client/data/documents/actor.d.mts +718 -64
  134. package/src/foundry/client/data/documents/adventure.d.mts +480 -46
  135. package/src/foundry/client/data/documents/ambient-light.d.mts +423 -19
  136. package/src/foundry/client/data/documents/ambient-sound.d.mts +473 -14
  137. package/src/foundry/client/data/documents/card.d.mts +567 -36
  138. package/src/foundry/client/data/documents/cards.d.mts +744 -87
  139. package/src/foundry/client/data/documents/chat-message.d.mts +574 -42
  140. package/src/foundry/client/data/documents/combat.d.mts +699 -69
  141. package/src/foundry/client/data/documents/combatant.d.mts +504 -24
  142. package/src/foundry/client/data/documents/drawing.d.mts +540 -14
  143. package/src/foundry/client/data/documents/fog-exploration.d.mts +416 -21
  144. package/src/foundry/client/data/documents/folder.d.mts +468 -35
  145. package/src/foundry/client/data/documents/index.d.mts +2 -0
  146. package/src/foundry/client/data/documents/item.d.mts +677 -20
  147. package/src/foundry/client/data/documents/journal-entry-page.d.mts +585 -19
  148. package/src/foundry/client/data/documents/journal-entry.d.mts +619 -18
  149. package/src/foundry/client/data/documents/macro.d.mts +528 -25
  150. package/src/foundry/client/data/documents/measured-template.d.mts +478 -14
  151. package/src/foundry/client/data/documents/note.d.mts +491 -15
  152. package/src/foundry/client/data/documents/playlist-sound.d.mts +426 -24
  153. package/src/foundry/client/data/documents/playlist.d.mts +665 -74
  154. package/src/foundry/client/data/documents/region-behavior.d.mts +507 -0
  155. package/src/foundry/client/data/documents/region.d.mts +784 -0
  156. package/src/foundry/client/data/documents/scene.d.mts +983 -147
  157. package/src/foundry/client/data/documents/setting.d.mts +395 -13
  158. package/src/foundry/client/data/documents/table-result.d.mts +476 -14
  159. package/src/foundry/client/data/documents/table.d.mts +661 -78
  160. package/src/foundry/client/data/documents/tile.d.mts +499 -14
  161. package/src/foundry/client/data/documents/token.d.mts +1111 -94
  162. package/src/foundry/client/data/documents/user.d.mts +493 -25
  163. package/src/foundry/client/data/documents/wall.d.mts +548 -14
  164. package/src/foundry/client/game.d.mts +60 -92
  165. package/src/foundry/client/head.d.mts +9 -9
  166. package/src/foundry/client/hooks.d.mts +257 -237
  167. package/src/foundry/client/pixi/board.d.mts +106 -94
  168. package/src/foundry/client/pixi/core/containers/base-canvas-group.d.mts +97 -25
  169. package/src/foundry/client/pixi/core/containers/cached-container.d.mts +37 -19
  170. package/src/foundry/client/pixi/core/containers/full-canvas-container.d.mts +7 -10
  171. package/src/foundry/client/pixi/core/containers/point-source-mesh.d.mts +25 -15
  172. package/src/foundry/client/pixi/core/containers/quad-mesh.d.mts +16 -6
  173. package/src/foundry/client/pixi/core/containers/quadtree.d.mts +113 -54
  174. package/src/foundry/client/pixi/core/containers/sprite-mesh.d.mts +69 -26
  175. package/src/foundry/client/pixi/core/containers/unbound-container.d.mts +20 -2
  176. package/src/foundry/client/pixi/core/interaction/canvas-animation.d.mts +164 -99
  177. package/src/foundry/client/pixi/core/interaction/control-icon.d.mts +61 -22
  178. package/src/foundry/client/pixi/core/interaction/mouse-handler.d.mts +120 -53
  179. package/src/foundry/client/pixi/core/interaction/ping.d.mts +62 -31
  180. package/src/foundry/client/pixi/core/interaction/pings/chevron.d.mts +23 -10
  181. package/src/foundry/client/pixi/core/interaction/pings/pulse.d.mts +91 -34
  182. package/src/foundry/client/pixi/core/interaction/render-flags.d.mts +76 -30
  183. package/src/foundry/client/pixi/core/interaction/resize-handle.d.mts +35 -5
  184. package/src/foundry/client/pixi/core/interaction/targets.d.mts +21 -18
  185. package/src/foundry/client/pixi/core/loader.d.mts +86 -76
  186. package/src/foundry/client/pixi/core/shapes/limited-angle-polygon.d.mts +42 -17
  187. package/src/foundry/client/pixi/core/shapes/polygon-mesher.d.mts +92 -64
  188. package/src/foundry/client/pixi/core/shapes/precise-text.d.mts +28 -10
  189. package/src/foundry/client/pixi/core/shapes/ray.d.mts +47 -23
  190. package/src/foundry/client/pixi/core/shapes/source-polygon.d.mts +170 -75
  191. package/src/foundry/client/pixi/extensions/circle.d.mts +128 -125
  192. package/src/foundry/client/pixi/extensions/graphics.d.mts +3 -1
  193. package/src/foundry/client/pixi/extensions/observable-transform.d.mts +5 -4
  194. package/src/foundry/client/pixi/extensions/polygon.d.mts +154 -134
  195. package/src/foundry/client/pixi/extensions/rectangle.d.mts +242 -259
  196. package/src/foundry/client/pixi/groups/effects.d.mts +75 -24
  197. package/src/foundry/client/pixi/groups/environment.d.mts +68 -19
  198. package/src/foundry/client/pixi/groups/hidden.d.mts +27 -11
  199. package/src/foundry/client/pixi/groups/interface.d.mts +62 -38
  200. package/src/foundry/client/pixi/groups/overlay.d.mts +19 -7
  201. package/src/foundry/client/pixi/groups/primary.d.mts +66 -44
  202. package/src/foundry/client/pixi/groups/rendered.d.mts +19 -7
  203. package/src/foundry/client/pixi/layers/base/canvas-layer.d.mts +11 -15
  204. package/src/foundry/client/pixi/layers/base/interaction-layer.d.mts +29 -28
  205. package/src/foundry/client/pixi/layers/base/placeables-layer.d.mts +306 -272
  206. package/src/foundry/client/pixi/layers/controls/cursor.d.mts +18 -9
  207. package/src/foundry/client/pixi/layers/controls/door.d.mts +32 -11
  208. package/src/foundry/client/pixi/layers/controls/layer.d.mts +89 -77
  209. package/src/foundry/client/pixi/layers/controls/ruler.d.mts +121 -96
  210. package/src/foundry/client/pixi/layers/effects/background-effects.d.mts +9 -12
  211. package/src/foundry/client/pixi/layers/effects/coloration-effects.d.mts +9 -10
  212. package/src/foundry/client/pixi/layers/effects/darkness-effects.d.mts +8 -8
  213. package/src/foundry/client/pixi/layers/effects/illumination-effects.d.mts +22 -22
  214. package/src/foundry/client/pixi/layers/effects/visibility.d.mts +106 -86
  215. package/src/foundry/client/pixi/layers/effects/weather/particles/effect.d.mts +14 -5
  216. package/src/foundry/client/pixi/layers/effects/weather/particles/leaves.d.mts +31 -2
  217. package/src/foundry/client/pixi/layers/effects/weather-effects.d.mts +137 -65
  218. package/src/foundry/client/pixi/layers/grid/highlight.d.mts +14 -4
  219. package/src/foundry/client/pixi/layers/grid/layer.d.mts +92 -92
  220. package/src/foundry/client/pixi/layers/grid/mesh.d.mts +37 -16
  221. package/src/foundry/client/pixi/layers/masks/depth.d.mts +12 -7
  222. package/src/foundry/client/pixi/layers/masks/occlusion.d.mts +19 -12
  223. package/src/foundry/client/pixi/layers/masks/vision.d.mts +104 -18
  224. package/src/foundry/client/pixi/layers/placeables/drawings.d.mts +16 -15
  225. package/src/foundry/client/pixi/layers/placeables/index.d.mts +1 -0
  226. package/src/foundry/client/pixi/layers/placeables/lighting.d.mts +12 -14
  227. package/src/foundry/client/pixi/layers/placeables/notes.d.mts +49 -32
  228. package/src/foundry/client/pixi/layers/placeables/regions.d.mts +113 -0
  229. package/src/foundry/client/pixi/layers/placeables/sounds.d.mts +81 -67
  230. package/src/foundry/client/pixi/layers/placeables/templates.d.mts +11 -15
  231. package/src/foundry/client/pixi/layers/placeables/tiles.d.mts +30 -21
  232. package/src/foundry/client/pixi/layers/placeables/tokens.d.mts +66 -52
  233. package/src/foundry/client/pixi/layers/placeables/walls.d.mts +54 -57
  234. package/src/foundry/client/pixi/perception/clockwise-sweep.d.mts +62 -27
  235. package/src/foundry/client/pixi/perception/detection-mode.d.mts +121 -47
  236. package/src/foundry/client/pixi/perception/fog.d.mts +38 -15
  237. package/src/foundry/client/pixi/perception/perception-manager.d.mts +136 -136
  238. package/src/foundry/client/pixi/perception/vision-mode.d.mts +91 -64
  239. package/src/foundry/client/pixi/perception/weiler-atherton-clipping.d.mts +44 -16
  240. package/src/foundry/client/pixi/placeable.d.mts +238 -137
  241. package/src/foundry/client/pixi/placeables/drawing.d.mts +255 -133
  242. package/src/foundry/client/pixi/placeables/index.d.mts +1 -0
  243. package/src/foundry/client/pixi/placeables/light.d.mts +199 -64
  244. package/src/foundry/client/pixi/placeables/note.d.mts +145 -54
  245. package/src/foundry/client/pixi/placeables/primary-canvas-objects/primary-canvas-object.d.mts +30 -8
  246. package/src/foundry/client/pixi/placeables/primary-canvas-objects/primary-graphics.d.mts +41 -11
  247. package/src/foundry/client/pixi/placeables/primary-canvas-objects/primary-occludable-object.d.mts +59 -18
  248. package/src/foundry/client/pixi/placeables/primary-canvas-objects/primary-sprite-mesh.d.mts +120 -37
  249. package/src/foundry/client/pixi/placeables/region.d.mts +280 -0
  250. package/src/foundry/client/pixi/placeables/sound.d.mts +205 -66
  251. package/src/foundry/client/pixi/placeables/template.d.mts +181 -100
  252. package/src/foundry/client/pixi/placeables/tile.d.mts +206 -140
  253. package/src/foundry/client/pixi/placeables/token.d.mts +916 -449
  254. package/src/foundry/client/pixi/placeables/wall.d.mts +249 -129
  255. package/src/foundry/client/pixi/webgl/extensions/batch-renderer.d.mts +72 -33
  256. package/src/foundry/client/pixi/webgl/extensions/batch-shader-generator.d.mts +10 -9
  257. package/src/foundry/client/pixi/webgl/helpers/{framebugger-snapshot.d.mts → framebuffer-snapshot.d.mts} +10 -9
  258. package/src/foundry/client/pixi/webgl/helpers/index.d.mts +1 -1
  259. package/src/foundry/client/pixi/webgl/helpers/smooth-noise.d.mts +38 -23
  260. package/src/foundry/client/pixi/webgl/helpers/texture-extractor.d.mts +82 -53
  261. package/src/foundry/client/pixi/webgl/shaders/base-shader-mixin.d.mts +12 -12
  262. package/src/foundry/client/pixi/webgl/shaders/base-shader.d.mts +45 -28
  263. package/src/foundry/client/pixi/webgl/shaders/filters/base-filter.d.mts +12 -11
  264. package/src/foundry/client/pixi/webgl/shaders/filters/base-mask-filter.d.mts +12 -10
  265. package/src/foundry/client/pixi/webgl/shaders/filters/blur.d.mts +22 -20
  266. package/src/foundry/client/pixi/webgl/shaders/filters/effects-masking.d.mts +36 -32
  267. package/src/foundry/client/pixi/webgl/shaders/filters/environment.d.mts +10 -9
  268. package/src/foundry/client/pixi/webgl/shaders/filters/glow-overlay.d.mts +12 -11
  269. package/src/foundry/client/pixi/webgl/shaders/filters/invisibility.d.mts +10 -9
  270. package/src/foundry/client/pixi/webgl/shaders/filters/outline-overlay.d.mts +12 -11
  271. package/src/foundry/client/pixi/webgl/shaders/filters/transition.d.mts +67 -60
  272. package/src/foundry/client/pixi/webgl/shaders/filters/visibility.d.mts +24 -17
  273. package/src/foundry/client/pixi/webgl/shaders/filters/vision-mask-filter.d.mts +13 -10
  274. package/src/foundry/client/pixi/webgl/shaders/filters/void.d.mts +10 -9
  275. package/src/foundry/client/pixi/webgl/shaders/filters/weather-occlusion-masks.d.mts +11 -10
  276. package/src/foundry/client/pixi/webgl/shaders/fragment-channel-mixin.d.mts +20 -14
  277. package/src/foundry/client/pixi/webgl/shaders/grid/grid.d.mts +12 -11
  278. package/src/foundry/client/pixi/webgl/shaders/lighting/background-lighting.d.mts +10 -9
  279. package/src/foundry/client/pixi/webgl/shaders/lighting/base-lighting.d.mts +33 -33
  280. package/src/foundry/client/pixi/webgl/shaders/lighting/coloration-lighting.d.mts +10 -9
  281. package/src/foundry/client/pixi/webgl/shaders/lighting/darkness-lighting.d.mts +10 -9
  282. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/bewitching-wave.d.mts +19 -17
  283. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/black-hole.d.mts +10 -9
  284. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/chroma.d.mts +10 -9
  285. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/emanation.d.mts +10 -9
  286. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/energy-field.d.mts +10 -9
  287. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/fairy-light.d.mts +19 -17
  288. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/flame.d.mts +19 -17
  289. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/fog.d.mts +10 -9
  290. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/force-grid.d.mts +10 -8
  291. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/ghost-light.d.mts +19 -17
  292. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/hexa-dome.d.mts +10 -9
  293. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/light-dome.d.mts +10 -9
  294. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/magical-gloom.d.mts +10 -9
  295. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/pulse.d.mts +19 -17
  296. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/radial-rainbow.d.mts +10 -9
  297. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/revolving-light.d.mts +10 -9
  298. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/roiling-mass.d.mts +10 -9
  299. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/siren-light.d.mts +19 -17
  300. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/smoke-patch.d.mts +20 -17
  301. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/star-light.d.mts +10 -9
  302. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/sunburst.d.mts +19 -17
  303. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/swirling-rainbow.d.mts +10 -9
  304. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/torch.d.mts +19 -17
  305. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/vortex.d.mts +19 -17
  306. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/wave.d.mts +19 -17
  307. package/src/foundry/client/pixi/webgl/shaders/lighting/illumination-lighting.d.mts +10 -9
  308. package/src/foundry/client/pixi/webgl/shaders/region/adjust-darkness-level.d.mts +71 -29
  309. package/src/foundry/client/pixi/webgl/shaders/region/base.d.mts +54 -10
  310. package/src/foundry/client/pixi/webgl/shaders/region/highlight.d.mts +69 -9
  311. package/src/foundry/client/pixi/webgl/shaders/samplers/base-sampler.d.mts +24 -25
  312. package/src/foundry/client/pixi/webgl/shaders/samplers/baseline-illumination.d.mts +10 -9
  313. package/src/foundry/client/pixi/webgl/shaders/samplers/color-adjustment.d.mts +38 -29
  314. package/src/foundry/client/pixi/webgl/shaders/samplers/depth.d.mts +21 -17
  315. package/src/foundry/client/pixi/webgl/shaders/samplers/fog-of-war.d.mts +10 -9
  316. package/src/foundry/client/pixi/webgl/shaders/samplers/occlusion.d.mts +20 -18
  317. package/src/foundry/client/pixi/webgl/shaders/samplers/primary.d.mts +11 -2
  318. package/src/foundry/client/pixi/webgl/shaders/samplers/token-ring.d.mts +28 -2
  319. package/src/foundry/client/pixi/webgl/shaders/vision/background-vision.d.mts +10 -9
  320. package/src/foundry/client/pixi/webgl/shaders/vision/base-vision.d.mts +11 -9
  321. package/src/foundry/client/pixi/webgl/shaders/vision/coloration-vision.d.mts +10 -9
  322. package/src/foundry/client/pixi/webgl/shaders/vision/effects/amplification.d.mts +10 -9
  323. package/src/foundry/client/pixi/webgl/shaders/vision/effects/wave.d.mts +19 -17
  324. package/src/foundry/client/pixi/webgl/shaders/vision/illumination-vision.d.mts +10 -9
  325. package/src/foundry/client/pixi/webgl/shaders/weather/base-weather.d.mts +40 -36
  326. package/src/foundry/client/pixi/webgl/shaders/weather/effect.d.mts +27 -33
  327. package/src/foundry/client/pixi/webgl/shaders/weather/fog.d.mts +17 -16
  328. package/src/foundry/client/pixi/webgl/shaders/weather/rain.d.mts +19 -18
  329. package/src/foundry/client/pixi/webgl/shaders/weather/snow.d.mts +15 -14
  330. package/src/foundry/client/pixi/workers/texture-worker.d.mts +33 -53
  331. package/src/foundry/client/tours/setup-tour.d.mts +15 -10
  332. package/src/foundry/client/ui/context.d.mts +48 -40
  333. package/src/foundry/client/ui/dialog.d.mts +137 -126
  334. package/src/foundry/client/ui/drag.d.mts +1 -1
  335. package/src/foundry/client/ui/dragdrop.d.mts +34 -28
  336. package/src/foundry/client/ui/editor.d.mts +29 -21
  337. package/src/foundry/client/ui/filepicker.d.mts +43 -38
  338. package/src/foundry/client/ui/filter.d.mts +62 -50
  339. package/src/foundry/client/ui/forms.d.mts +22 -22
  340. package/src/foundry/client/ui/notifications.d.mts +10 -3
  341. package/src/foundry/client/ui/prosemirror.d.mts +15 -7
  342. package/src/foundry/client/ui/secrets.d.mts +42 -27
  343. package/src/foundry/client/ui/tabs.d.mts +40 -33
  344. package/src/foundry/client-esm/applications/_module.d.mts +3 -3
  345. package/src/foundry/client-esm/applications/_types.d.mts +0 -2
  346. package/src/foundry/client-esm/applications/api/_module.d.mts +2 -2
  347. package/src/foundry/client-esm/applications/api/application.d.mts +36 -19
  348. package/src/foundry/client-esm/applications/api/dialog.d.mts +20 -22
  349. package/src/foundry/client-esm/applications/api/document-sheet.d.mts +26 -12
  350. package/src/foundry/client-esm/applications/api/handlebars-application.d.mts +142 -126
  351. package/src/foundry/client-esm/applications/apps/_module.d.mts +2 -2
  352. package/src/foundry/client-esm/applications/apps/compendium-art-config.d.mts +10 -10
  353. package/src/foundry/client-esm/applications/apps/permission-config.d.mts +3 -3
  354. package/src/foundry/client-esm/applications/dice/_module.d.mts +2 -2
  355. package/src/foundry/client-esm/applications/dice/roll-resolver.d.mts +14 -2
  356. package/src/foundry/client-esm/applications/elements/_module.d.mts +2 -2
  357. package/src/foundry/client-esm/applications/elements/document-tags.d.mts +2 -0
  358. package/src/foundry/client-esm/applications/elements/file-picker.d.mts +1 -1
  359. package/src/foundry/client-esm/applications/elements/multi-select.d.mts +15 -5
  360. package/src/foundry/client-esm/applications/elements/string-tags.d.mts +1 -1
  361. package/src/foundry/client-esm/applications/forms/fields.d.mts +1 -1
  362. package/src/foundry/client-esm/applications/sheets/_module.d.mts +2 -2
  363. package/src/foundry/client-esm/applications/sheets/actor-sheet.d.mts +3 -3
  364. package/src/foundry/client-esm/applications/sheets/ambient-light-config.d.mts +10 -8
  365. package/src/foundry/client-esm/applications/sheets/ambient-sound-config.d.mts +9 -7
  366. package/src/foundry/client-esm/applications/sheets/item-sheet.d.mts +3 -3
  367. package/src/foundry/client-esm/applications/sheets/region-behavior-config.d.mts +30 -5
  368. package/src/foundry/client-esm/applications/sheets/region-config.d.mts +36 -5
  369. package/src/foundry/client-esm/applications/sheets/user-config.d.mts +8 -7
  370. package/src/foundry/client-esm/applications/ui/_module.d.mts +2 -2
  371. package/src/foundry/client-esm/applications/ui/region-legend.d.mts +45 -3
  372. package/src/foundry/client-esm/audio/_module.d.mts +2 -3
  373. package/src/foundry/client-esm/audio/_types.d.mts +2 -0
  374. package/src/foundry/client-esm/audio/biquad.d.mts +76 -26
  375. package/src/foundry/client-esm/audio/cache.d.mts +31 -20
  376. package/src/foundry/client-esm/audio/convolver.d.mts +47 -25
  377. package/src/foundry/client-esm/audio/helper.d.mts +124 -80
  378. package/src/foundry/client-esm/audio/sound.d.mts +230 -126
  379. package/src/foundry/client-esm/audio/timeout.d.mts +28 -12
  380. package/src/foundry/client-esm/canvas/_module.d.mts +2 -2
  381. package/src/foundry/client-esm/canvas/edges/_module.d.mts +2 -2
  382. package/src/foundry/client-esm/canvas/edges/collision.d.mts +69 -18
  383. package/src/foundry/client-esm/canvas/edges/edge.d.mts +110 -41
  384. package/src/foundry/client-esm/canvas/edges/edges.d.mts +10 -0
  385. package/src/foundry/client-esm/canvas/edges/vertex.d.mts +56 -26
  386. package/src/foundry/client-esm/canvas/regions/_module.d.mts +6 -11
  387. package/src/foundry/client-esm/canvas/regions/geometry.d.mts +38 -0
  388. package/src/foundry/client-esm/canvas/regions/mesh.d.mts +72 -0
  389. package/src/foundry/client-esm/canvas/regions/polygon-tree.d.mts +130 -0
  390. package/src/foundry/client-esm/canvas/regions/shape.d.mts +129 -0
  391. package/src/foundry/client-esm/canvas/scene-manager.d.mts +13 -3
  392. package/src/foundry/client-esm/canvas/smaa/blend.d.mts +14 -3
  393. package/src/foundry/client-esm/canvas/smaa/edges.d.mts +25 -3
  394. package/src/foundry/client-esm/canvas/smaa/smaa.d.mts +121 -23
  395. package/src/foundry/client-esm/canvas/smaa/weights.d.mts +26 -3
  396. package/src/foundry/client-esm/canvas/sources/_module.d.mts +2 -2
  397. package/src/foundry/client-esm/canvas/sources/base-effect-source.d.mts +84 -40
  398. package/src/foundry/client-esm/canvas/sources/base-light-source.d.mts +103 -39
  399. package/src/foundry/client-esm/canvas/sources/global-light-source.d.mts +89 -15
  400. package/src/foundry/client-esm/canvas/sources/point-darkness-source.d.mts +71 -27
  401. package/src/foundry/client-esm/canvas/sources/point-effect-source.d.mts +49 -20
  402. package/src/foundry/client-esm/canvas/sources/point-light-source.d.mts +57 -16
  403. package/src/foundry/client-esm/canvas/sources/point-movement-source.d.mts +31 -4
  404. package/src/foundry/client-esm/canvas/sources/point-sound-source.d.mts +45 -12
  405. package/src/foundry/client-esm/canvas/sources/point-vision-source.d.mts +98 -52
  406. package/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts +180 -69
  407. package/src/foundry/client-esm/canvas/tokens/_module.d.mts +2 -3
  408. package/src/foundry/client-esm/canvas/tokens/ring-config.d.mts +175 -2
  409. package/src/foundry/client-esm/canvas/tokens/ring-data.d.mts +141 -2
  410. package/src/foundry/client-esm/canvas/tokens/ring.d.mts +284 -2
  411. package/src/foundry/client-esm/client.d.mts +47 -54
  412. package/src/foundry/client-esm/data/_module.d.mts +2 -2
  413. package/src/foundry/client-esm/data/client-backend.d.mts +22 -23
  414. package/src/foundry/client-esm/data/region-behaviors/_module.d.mts +11 -14
  415. package/src/foundry/client-esm/data/region-behaviors/adjust-darkness-level.d.mts +57 -0
  416. package/src/foundry/client-esm/data/region-behaviors/base.d.mts +59 -0
  417. package/src/foundry/client-esm/data/region-behaviors/display-scrolling-text.d.mts +64 -0
  418. package/src/foundry/client-esm/data/region-behaviors/execute-macro.d.mts +27 -0
  419. package/src/foundry/client-esm/data/region-behaviors/execute-script.d.mts +23 -0
  420. package/src/foundry/client-esm/data/region-behaviors/pause-game.d.mts +23 -0
  421. package/src/foundry/client-esm/data/region-behaviors/suppress-weather.d.mts +17 -0
  422. package/src/foundry/client-esm/data/region-behaviors/teleport-token.d.mts +32 -0
  423. package/src/foundry/client-esm/data/region-behaviors/toggle-behavior.d.mts +31 -0
  424. package/src/foundry/client-esm/dice/_module.d.mts +2 -3
  425. package/src/foundry/client-esm/dice/parser.d.mts +11 -25
  426. package/src/foundry/client-esm/dice/roll.d.mts +115 -89
  427. package/src/foundry/client-esm/dice/terms/_module.d.mts +2 -3
  428. package/src/foundry/client-esm/dice/terms/coin.d.mts +8 -5
  429. package/src/foundry/client-esm/dice/terms/dice.d.mts +93 -63
  430. package/src/foundry/client-esm/dice/terms/die.d.mts +11 -4
  431. package/src/foundry/client-esm/dice/terms/fate.d.mts +9 -2
  432. package/src/foundry/client-esm/dice/terms/function.d.mts +18 -18
  433. package/src/foundry/client-esm/dice/terms/numeric.d.mts +3 -5
  434. package/src/foundry/client-esm/dice/terms/operator.d.mts +2 -2
  435. package/src/foundry/client-esm/dice/terms/parenthetical.d.mts +9 -10
  436. package/src/foundry/client-esm/dice/terms/pool.d.mts +25 -31
  437. package/src/foundry/client-esm/dice/terms/string.d.mts +4 -4
  438. package/src/foundry/client-esm/dice/terms/term.d.mts +18 -4
  439. package/src/foundry/client-esm/dice/twister.d.mts +3 -3
  440. package/src/foundry/client-esm/helpers/_module.d.mts +2 -2
  441. package/src/foundry/client-esm/helpers/_types.d.mts +12 -46
  442. package/src/foundry/client-esm/helpers/compendium-art.d.mts +56 -4
  443. package/src/foundry/common/abstract/_types.d.mts +60 -54
  444. package/src/foundry/common/abstract/backend.d.mts +51 -45
  445. package/src/foundry/common/abstract/data.d.mts +132 -154
  446. package/src/foundry/common/abstract/document.d.mts +1306 -438
  447. package/src/foundry/common/abstract/embedded-collection-delta.d.mts +1 -1
  448. package/src/foundry/common/abstract/embedded-collection.d.mts +37 -7
  449. package/src/foundry/common/abstract/module.d.mts +3 -2
  450. package/src/foundry/common/abstract/singleton-collection.d.mts +1 -1
  451. package/src/foundry/common/abstract/socket.d.mts +1 -1
  452. package/src/foundry/common/abstract/type-data.d.mts +58 -55
  453. package/src/foundry/common/config.d.mts +5 -3
  454. package/src/foundry/common/constants.d.mts +261 -231
  455. package/src/foundry/common/data/data.d.mts +200 -94
  456. package/src/foundry/common/data/fields.d.mts +700 -644
  457. package/src/foundry/common/data/module.d.mts +2 -2
  458. package/src/foundry/common/data/validation-failure.d.mts +12 -9
  459. package/src/foundry/common/documents/_module.d.mts +4 -2
  460. package/src/foundry/common/documents/_types.d.mts +22 -50
  461. package/src/foundry/common/documents/active-effect.d.mts +280 -179
  462. package/src/foundry/common/documents/actor-delta.d.mts +318 -69
  463. package/src/foundry/common/documents/actor.d.mts +305 -117
  464. package/src/foundry/common/documents/adventure.d.mts +266 -141
  465. package/src/foundry/common/documents/ambient-light.d.mts +268 -75
  466. package/src/foundry/common/documents/ambient-sound.d.mts +268 -109
  467. package/src/foundry/common/documents/card.d.mts +267 -174
  468. package/src/foundry/common/documents/cards.d.mts +299 -126
  469. package/src/foundry/common/documents/chat-message.d.mts +276 -158
  470. package/src/foundry/common/documents/combat.d.mts +300 -89
  471. package/src/foundry/common/documents/combatant.d.mts +275 -88
  472. package/src/foundry/common/documents/drawing.d.mts +286 -206
  473. package/src/foundry/common/documents/fog-exploration.d.mts +258 -70
  474. package/src/foundry/common/documents/folder.d.mts +252 -81
  475. package/src/foundry/common/documents/item.d.mts +305 -99
  476. package/src/foundry/common/documents/journal-entry-page.d.mts +279 -189
  477. package/src/foundry/common/documents/journal-entry.d.mts +294 -68
  478. package/src/foundry/common/documents/macro.d.mts +254 -132
  479. package/src/foundry/common/documents/measured-template.d.mts +293 -139
  480. package/src/foundry/common/documents/note.d.mts +274 -149
  481. package/src/foundry/common/documents/playlist-sound.d.mts +260 -94
  482. package/src/foundry/common/documents/playlist.d.mts +279 -120
  483. package/src/foundry/common/documents/region-behavior.d.mts +329 -0
  484. package/src/foundry/common/documents/region.d.mts +327 -0
  485. package/src/foundry/common/documents/roll-table.d.mts +286 -102
  486. package/src/foundry/common/documents/scene.d.mts +276 -336
  487. package/src/foundry/common/documents/setting.d.mts +229 -54
  488. package/src/foundry/common/documents/table-result.d.mts +267 -94
  489. package/src/foundry/common/documents/tile.d.mts +301 -170
  490. package/src/foundry/common/documents/token.d.mts +351 -445
  491. package/src/foundry/common/documents/user.d.mts +256 -144
  492. package/src/foundry/common/documents/wall.d.mts +273 -156
  493. package/src/foundry/common/grid/_module.d.mts +3 -3
  494. package/src/foundry/common/grid/base.d.mts +66 -49
  495. package/src/foundry/common/grid/gridless.d.mts +2 -2
  496. package/src/foundry/common/grid/hexagonal.d.mts +35 -28
  497. package/src/foundry/common/grid/square.d.mts +3 -3
  498. package/src/foundry/common/packages/base-module.d.mts +6 -24
  499. package/src/foundry/common/packages/base-package.d.mts +23 -21
  500. package/src/foundry/common/packages/base-system.d.mts +6 -63
  501. package/src/foundry/common/packages/base-world.d.mts +8 -61
  502. package/src/foundry/common/packages/module.d.mts +7 -7
  503. package/src/foundry/common/packages/sub-types.d.mts +2 -2
  504. package/src/foundry/common/primitives/array.d.mts +4 -4
  505. package/src/foundry/common/primitives/math.d.mts +7 -1
  506. package/src/foundry/common/primitives/number.d.mts +2 -2
  507. package/src/foundry/common/primitives/set.d.mts +17 -14
  508. package/src/foundry/common/primitives/string.d.mts +1 -1
  509. package/src/foundry/common/prosemirror/_module.d.mts +15 -15
  510. package/src/foundry/common/prosemirror/dirty-plugin.d.mts +1 -1
  511. package/src/foundry/common/prosemirror/dom-parser.d.mts +2 -1
  512. package/src/foundry/common/prosemirror/dropdown.d.mts +1 -1
  513. package/src/foundry/common/prosemirror/highlight-matches-plugin.d.mts +2 -2
  514. package/src/foundry/common/prosemirror/image-plugin.d.mts +1 -1
  515. package/src/foundry/common/prosemirror/menu.d.mts +3 -3
  516. package/src/foundry/common/prosemirror/paste-transformer.d.mts +1 -1
  517. package/src/foundry/common/prosemirror/plugin.d.mts +2 -2
  518. package/src/foundry/common/prosemirror/schema/index.d.mts +0 -1
  519. package/src/foundry/common/prosemirror/schema/lists.d.mts +2 -0
  520. package/src/foundry/common/prosemirror/util.d.mts +1 -1
  521. package/src/foundry/common/types.d.mts +3 -3
  522. package/src/foundry/common/utils/bitmask.d.mts +23 -11
  523. package/src/foundry/common/utils/collection.d.mts +61 -38
  524. package/src/foundry/common/utils/color.d.mts +20 -2
  525. package/src/foundry/common/utils/event-emitter.d.mts +32 -17
  526. package/src/foundry/common/utils/helpers.d.mts +36 -26
  527. package/src/foundry/common/utils/http.d.mts +2 -2
  528. package/src/foundry/common/utils/module.d.mts +2 -2
  529. package/src/foundry/common/utils/string-tree.d.mts +45 -39
  530. package/src/foundry/common/utils/word-tree.d.mts +10 -23
  531. package/src/foundry/index.d.mts +0 -1
  532. package/src/foundry/{clipper → public/scripts/clipper}/clipper.d.mts +58 -16
  533. package/src/foundry/public/scripts/index.d.mts +1 -0
  534. package/src/foundry/public/scripts/workers/image-compressor.d.mts +23 -0
  535. package/src/foundry/public/scripts/workers/index.d.mts +1 -0
  536. package/{index-lenient.d.mts → src/index-lenient.d.mts} +2 -0
  537. package/src/index.d.mts +6 -0
  538. package/src/tsconfig.json +15 -0
  539. package/src/types/augments/particles.d.mts +29 -0
  540. package/src/types/augments/pixi.d.mts +1024 -21
  541. package/src/types/augments/smooth.d.mts +31 -0
  542. package/src/types/augments/tinyMCE.d.mts +1 -1
  543. package/src/types/config.d.mts +20 -312
  544. package/src/types/documentConfiguration.d.mts +286 -542
  545. package/src/types/index.d.mts +1 -1
  546. package/src/types/lib.d.mts +12 -0
  547. package/src/types/workers/image-compressor.d.mts +176 -0
  548. package/src/utils/index.d.mts +1279 -0
  549. package/tsconfig.json +29 -0
  550. package/tsconfig.main.json +8 -0
  551. package/tsconfig.miscellaneous.json +16 -0
  552. package/index.d.mts +0 -5
  553. package/src/foundry/client/apps/placeables/light-config.d.mts +0 -100
  554. package/src/foundry/client/apps/placeables/sound-config.d.mts +0 -43
  555. package/src/foundry/common/documents/module.d.mts +0 -35
  556. package/src/foundry/common/primitives/regex.d.mts +0 -12
  557. package/src/types/helperTypes.d.mts +0 -583
  558. package/src/types/utils.d.mts +0 -539
  559. /package/src/foundry/{clipper → public/scripts/clipper}/index.d.mts +0 -0
@@ -0,0 +1,1279 @@
1
+ import type { Document } from "../foundry/common/abstract/module.d.mts";
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
4
+ type ConfiguredModuleData<Name extends string> = Name extends keyof ModuleConfig ? ModuleConfig[Name] : {};
5
+
6
+ /**
7
+ * This type exists due to https://github.com/microsoft/TypeScript/issues/55667
8
+ * This will be deprecated once this issue is solved.
9
+ */
10
+ export type FixedInstanceType<T extends abstract new (...args: never) => any> = T extends abstract new (
11
+ ...args: infer _
12
+ ) => infer R
13
+ ? R
14
+ : never;
15
+
16
+ export type ConfiguredModule<Name extends string> = Name extends keyof RequiredModules
17
+ ? ConfiguredModuleData<Name>
18
+ :
19
+ | ({ active: true } & ConfiguredModuleData<Name>)
20
+ // flawed, can't use `key in module` this way, but omitting the Partial Record type kills nullish
21
+ // collocating, which is probably the better DX.
22
+ | ({ active: false } & Record<keyof ConfiguredModuleData<Name>, undefined>);
23
+
24
+ /** Keys of functions of console.log / globalThis.logger */
25
+ export type LoggingLevels = "debug" | "log" | "info" | "warn" | "error";
26
+
27
+ /**
28
+ * `GetKey` accesses a property while intentionally ignoring index signatures. This means `GetKey<Record<string, unknown>, "foo">` will return `never`.
29
+ */
30
+ // Note(LukeAbby): There are two tricky cases:
31
+ // - `T = {}` would regularly always return `unknown`. The fix here adding a single dummy property with `{ _?: unknown } & T`.
32
+ // - `T = never` would regularly always return `unknown`. The fix here is checking if `any` is assignable to it.
33
+ export type GetKey<T, K extends PropertyKey, D = never> = [any] extends [T] ? _GetKey<{ _?: unknown } & T, K, D> : D;
34
+
35
+ type _GetKey<T, K extends PropertyKey, D> = T extends { readonly [_ in K]?: infer V } ? V : D;
36
+
37
+ /**
38
+ * `Partial` is usually the wrong type.
39
+ * In order to make it easier to audit unintentional uses of `Partial` this type is provided.
40
+ * Also allows specifying certain keys to make partial.
41
+ *
42
+ * ### Picking the right helper type
43
+ * - Favor `NullishProps` whenever it is valid. Allowing both `null` and
44
+ * `undefined` is convenient for the end user and it is very common that
45
+ * wherever `undefined` is valid so is `null`. For some examples it is valid
46
+ * for `options.prop ??= "default"`, `options.prop ||= "default"`,
47
+ * `if (options.prop) { ... }`, `if (options.prop == null)`, or so on.
48
+ * - Use `IntentionalPartial` when an explicit `undefined` is problematic but
49
+ * leaving off the property entirely is fine. This primarily occurs when
50
+ * patterns like `options = { ...defaultOptions, ...options }`,
51
+ * `Object.assign({}, defaultOptions, options)`,
52
+ * `foundry.utils.mergeObject(defaultOptions, options)`, or so on.
53
+ *
54
+ * Note that {@link foundry.utils.mergeObject | `foundry.utils.mergeObject`}
55
+ * also expands the object. So once `ExpandsTo` exists you should also use
56
+ * that helper type.
57
+ *
58
+ * What these patterns have in common is that if `options` looks like
59
+ * `{ prop: undefined }` that will override whatever is in `defaultOptions`
60
+ * and may cause issues. Note that even if you see one of these patterns you
61
+ * also need to ensure that `undefined` would cause issues down the road
62
+ * before using `IntentionalPartial` as it could be an intended way of
63
+ * resetting a property.
64
+ * - Use `InexactPartial` when `null` is problematic but `undefined` is not.
65
+ * The most common time this shows up is with the pattern
66
+ * `exampleFunction({ prop = "foo" } = {}) { ... }`.
67
+ */
68
+ export type IntentionalPartial<T extends object, K extends AllKeysOf<T> = AllKeysOf<T>> = PrettifyType<
69
+ {
70
+ [K2 in keyof T as Extract<K2, K>]?: T[K2];
71
+ } & {
72
+ // Note(LukeAbby): This effectively inlines `Omit<T, K>`, hoping for
73
+ [K2 in keyof T as Exclude<K2, K>]: T[K2];
74
+ }
75
+ >;
76
+
77
+ /**
78
+ * This type is used to make a constraint where `T` must be statically known to overlap with `U`.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * // The `const T` allows inference to be a bit more specific. This is useful for a utility type like this.`
83
+ * function takesNumber<const T>(input: OverlapsWith<T, number>): void {
84
+ * // This function body is an example of a method this might be useful for.
85
+ * // If the input isn't an number it simply returns in this case.
86
+ * if (typeof input !== "number") {
87
+ * return;
88
+ * }
89
+ *
90
+ * // Assumes, unchecked, that `element` is a number.
91
+ * // This means an input like `number[] | string[]` would be unsound as it could be a string.
92
+ * element + 1;
93
+ * }
94
+ *
95
+ * takesNumber(1); // Ok!
96
+ * takesNumber("foo"); // Error, statically known to never an number and so presumed to be a mistake.
97
+ * takesNumber(Math.random() > 0.5 ? 1 : "foo"); // Ok, `"foo"` doesn't actually cause any runtime issues, it was just disallowed above because then it'd never do anything useful.
98
+ * ```
99
+ */
100
+ export type OverlapsWith<T, U> = [Extract<T, U>, any] extends [U, Extract<T, U>] ? T : U extends T ? T : U;
101
+
102
+ /**
103
+ * Used to build a constraint where `T` to overlap with `Item[]` but disallows unrelated arrays.
104
+ * This is safer than what `OverlapsWith` provides as it ensures that if the type is an array it is an array of `Item`.
105
+ * Assumes readonly arrays are permitted.
106
+ *
107
+ * Note that `never[]` and `any[]` are still accepted due to the fundamental nature of these types.
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * // The `const T` allows inference to be a bit more specific. This is useful for a utility type like this.`
112
+ * function takesNumericArray<const T>(input: ArrayOverlaps<T, number>): void {
113
+ * // This function body is an example of a method this might be useful for.
114
+ * // If the input isn't an array it simply returns in this case.
115
+ * if (!Array.isArray(input)) {
116
+ * return;
117
+ * }
118
+ *
119
+ * for (const element of input) {
120
+ * // Assumes, unchecked, that `element` is a number.
121
+ * // This means an input like `number[] | string[]` would be unsound as it could be a string.
122
+ * element + 1;
123
+ * }
124
+ * }
125
+ *
126
+ * takesNumericArray([1, 2, 3]); // Ok!
127
+ * takesNumericArray("foo"); // Error, statically known to never an array and so presumed to be a mistake.
128
+ * takesNumericArray(Math.random() > 0.5 ? [1, 2, 3] : "foo"); // Ok, `"foo"` doesn't actually cause any runtime issues, it was just disallowed above because then it'd never do anything useful.
129
+ * takesNumericArray(Math.random() > 0.5 ? [1, 2, 3] : ["foo", "bar"]); // Error, at runtime it could be an array of the wrong type and that isn't handled. Notably this would succeed with `OverlapsWith`.
130
+ * ```
131
+ */
132
+ export type ArrayOverlaps<Arr, T> =
133
+ Extract<Arr, readonly unknown[]> extends readonly T[] ? OverlapsWith<Arr, readonly T[]> : readonly T[];
134
+
135
+ /**
136
+ * Use this whenever a type is given that should match some constraint but is
137
+ * not guaranteed to. For example when additional properties can be declaration
138
+ * merged into an interface. When the type does not conform then `ConformTo` is
139
+ * used instead.
140
+ *
141
+ * See `MustConform` for a version that throws a compilation error when the type
142
+ * cannot be statically known to conform.
143
+ */
144
+ export type MakeConform<T, ConformTo, D extends ConformTo = ConformTo> = [T] extends [ConformTo] ? T : D;
145
+
146
+ /**
147
+ * This is useful when you want to ensure that a type conforms to a certain
148
+ * constraint. If it is not guaranteed to conform then a compilation error is
149
+ * thrown. This makes it too conservative in some cases.
150
+ */
151
+ export type MustConform<T extends ConformTo, ConformTo> = T;
152
+
153
+ /**
154
+ * This allows you to treat all interfaces as a plain object. But beware, if the
155
+ * interface represents a function, array, or constructor then these will be
156
+ * stripped from the interface.
157
+ *
158
+ * This is generally intended for cases where an interface is given in order to
159
+ * be declaration merged and then must be assigned to a plain object type.
160
+ *
161
+ * The constraint `T extends object` is used because `object` includes functions
162
+ * and arrays etc. This is crucial to allow interfaces to be given to this type.
163
+ */
164
+ export type InterfaceToObject<T extends object> = {
165
+ // This mapped type would be a no-op on most types (even primitives like string)
166
+ // but for functions, classes, and arrays they convert them to "proper" objects by
167
+ // stripping constructors/function signatures. One side effect is a type like
168
+ // `() => number` will result in `{}`.
169
+ [K in keyof T]: T[K];
170
+ };
171
+
172
+ /**
173
+ * This is a helper type that allows you to ensure that a record conforms to a
174
+ * certain shape. This is useful when you want to ensure that a record has all
175
+ * keys of a certain type.
176
+ *
177
+ * When a value does not conform it is replaced with `never` to indicate that
178
+ * there is an issue.
179
+ */
180
+ export type ConformRecord<T extends object, V, D extends V = V> = {
181
+ [K in keyof T]: T[K] extends V ? T[K] : D;
182
+ };
183
+
184
+ /**
185
+ * Converts a regular function type into a function derived from a method.
186
+ *
187
+ * Methods have a special exception in TypeScript that allows unsound subtyping
188
+ * that unfortunately has been deeply engrained into not just JavaScript codebases
189
+ * but the core APIs of JavaScript itself in the DOM.
190
+ *
191
+ * It might seem odd to want to opt-in to this unsoundness but it's unfortunately
192
+ * useful in several cases, such as when you have a property like
193
+ * `prop: ((arg: Options) => number) | undefined` and you want to meet the expectations
194
+ * from other similar methods.
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * declare class ExampleBaseClass {
199
+ * // This demonstrates a typical example of where the allowed unsoundness is useful.
200
+ * methodOne(arg: { x: string }): number;
201
+ *
202
+ * // This helps demonstrates an example that may be easier to recognize as unsound.
203
+ * methodTwo(arg: string): number;
204
+ *
205
+ * functionProperty: (arg: string) => number;
206
+ * methodLikeProperty: ToMethod<(arg: string) => number>;
207
+ * }
208
+ *
209
+ * // TypeScript allows this without any errors.
210
+ * declare class MethodSubclassing extends ExampleBaseClass {
211
+ * // It's a very common thing for subclasses to ask for extra properties.
212
+ * // This appears in the DOM APIs.
213
+ * methodOne(arg: { x: string; y: string }): number;
214
+ *
215
+ * // Only taking `"foo" | "bar"` should seem pretty unsound.
216
+ * // The above is actually equally unsound but it's less obvious to many people.
217
+ * methodTwo(arg: "foo" | "bar"): number;
218
+ * }
219
+ *
220
+ * // This is allowed. If it wasn't subclassing would be less useful.
221
+ * const exampleMethodSubclass: ExampleBaseClass = new MethodSubclassing();
222
+ *
223
+ * // TypeScript does not error here. However at runtime `MethodSubclassing#methodOne`
224
+ * // will almost certainly error as it has the required property `y`.
225
+ * // The reason why there's no errors is an intentional unsoundness in TypeScript.
226
+ * exampleMethodSubclass.methodOne({ x: "foo" });
227
+ *
228
+ * // Similarly this is allowed.
229
+ * // Both methods show taking arguments that are 'subtypes' of the original.
230
+ * // In the case of functions this is unsound as demonstrated because in both
231
+ * // examples you're substituting a function that has to be able to be called
232
+ * // with a wide variety of arguments with one that will error for many of them.
233
+ * exampleMethodSubclass.methodTwo("lorem");
234
+ *
235
+ * declare class PropertySubclassing extends ExampleBaseClass {
236
+ * // This errors right here. This preventative error is because of the prior
237
+ * // explained unsoundness. It errors here because there's really only 3
238
+ * // places to error at compile time to prevent a runtime error:
239
+ * // 1. At the call site when a subclass is used unsoundly. Unfortunately
240
+ * // at this point it's too late to know for certain if it's a subclass
241
+ * // or not. For example there could be a guarded condition to avoid
242
+ * // subclasses that TypeScript can't possibly track.
243
+ * // 2. When trying to assign `PropertySubclassing` to `ExampleBaseClass`.
244
+ * // This would be a feasible alternative but would likely come as a
245
+ * // surprise as the subclass could have been used for quite a while
246
+ * // before trying to be assigned to its superclass.
247
+ * // 3. Error at the definition. This is where TypeScript has chosen to error.
248
+ * // The error is unfortunately not the most intuitive but it is correct.
249
+ * functionProperty: (arg: "foo" | "bar") => number;
250
+ * }
251
+ *
252
+ * declare class MethodLikeSubclassing extends ExampleBaseClass {
253
+ * // This is unsound but by using the `ToMethod` in the parent class it's allowed.
254
+ * methodLikeProperty: (arg: "foo" | "bar") => number;
255
+ * }
256
+ * ```
257
+ *
258
+ * The TypeScript FAQ explains this in a way that may either be intuitive and
259
+ * explain all lingering questions or be confusing and muddle the waters.
260
+ * It's also worth mentioning that it claims all function parameters work this way,
261
+ * this behavior is disabled for functions in most codebases (including this one)
262
+ * because of the `strictFunctionTypes` compiler flag, implicit under `strict: true`.
263
+ * See: https://github.com/Microsoft/TypeScript/wiki/FAQ#why-are-function-parameters-bivariant
264
+ *
265
+ * Note that this does not work well with exotic functions. Unexpected behavior may occur with:
266
+ * - Overloaded functions.
267
+ * - Functions with additional properties, e.g. `(() => number) & { prop: string }`.
268
+ * - Functions of the shape `(...args: never[]) => T`.
269
+ */
270
+ export type ToMethod<T extends AnyFunction> = {
271
+ method(...args: Parameters<T>): ReturnType<T>;
272
+ }["method"];
273
+
274
+ export type ConfiguredSheetClass<T extends Document.AnyConstructor> = GetKey<
275
+ GetKey<CONFIG, T["metadata"]["name"]>,
276
+ "sheetClass",
277
+ T
278
+ >;
279
+
280
+ export type ObjectClass<T extends Document.AnyConstructor> = GetKey<
281
+ GetKey<CONFIG, T["metadata"]["name"]>,
282
+ "objectClass",
283
+ T
284
+ >;
285
+
286
+ export type LayerClass<T extends Document.AnyConstructor> = GetKey<
287
+ GetKey<CONFIG, T["metadata"]["name"]>,
288
+ "layerClass",
289
+ T
290
+ >;
291
+
292
+ /**
293
+ * Actual document types that go in folders
294
+ */
295
+ export type FolderDocumentTypes = Exclude<foundry.CONST.FOLDER_DOCUMENT_TYPES, "Compendium">;
296
+
297
+ export type MaybeEmpty<T extends AnyObject> =
298
+ | T
299
+ | {
300
+ [K in keyof T]?: never;
301
+ };
302
+
303
+ /**
304
+ * The following uses `extends object` instead of `AnyObject` to allow `O = typeof SomeClass`
305
+ */
306
+ export type PropertiesOfType<O extends object, T> = {
307
+ [K in keyof O]: [O[K], T] extends [T, O[K]] ? K : never;
308
+ }[keyof O];
309
+
310
+ declare class Branded<in out BrandName extends string> {
311
+ #brand: BrandName;
312
+ }
313
+
314
+ /**
315
+ * Brands a type such that is behaves just like the input type while preventing
316
+ * assignment to it. This is useful to create types that indicate a specific
317
+ * invariant that the type must adhere to that a more basic type wouldn't have.
318
+ *
319
+ * Note: You can brand most types but due to its implementation this
320
+ * helper is incompatible with `any`, `unknown`, and `never`. See "Brand Implementation"
321
+ * for more details.
322
+ *
323
+ * For example enum members can be branded to prevent an arbitrary number from
324
+ * being mistakenly used in their place:
325
+ *
326
+ * @example
327
+ * ```ts
328
+ * type NUMBER_ENUM = Brand<number, "NUMBER_ENUM">;
329
+ *
330
+ * const NUMBER_ENUM: {
331
+ * X: NUMBER_ENUM,
332
+ * Y: NUMBER_ENUM
333
+ * };
334
+ *
335
+ * function useNumberEnum(value: NUMBER_ENUM) { ... }
336
+ * usesNumberEnum(NUMBER_ENUM.X); // Works.
337
+ * usesNumberEnum(1); // Error.
338
+ * ```
339
+ *
340
+ * ### Brand Implementation
341
+ *
342
+ * The fundamental trick of the implementation is that it intersects the base
343
+ * type with a compile-time only marker property. This marker property will not
344
+ * exist on the base type and so prevents assignment just like how `{ foo: string }`
345
+ * can't be assigned to `{ foo: string; bar: number }` because it's missing a property.
346
+ *
347
+ * A more basic implementation might look like this:
348
+ *
349
+ * ```ts
350
+ * type Brand<BaseType, BrandName extends string> = BaseType & { brandType: BrandName };
351
+ * ```
352
+ *
353
+ * But this has two problems:
354
+ * - In theory anyone can add this `brandType` property.
355
+ * - The `brandType` property is accessible and visible, e.g.
356
+ * `keyof Brand<BaseType, BrandName>` would include `brandType` because it's a visible property.
357
+ *
358
+ * The implementation here solves both of these problems by using a private class field.
359
+ * This class is unexported and so due to the way that private class properties work this
360
+ * means there is no other way to create a compatible property (outside of `any`). Using a
361
+ * class also has the added benefit that the type parameter can be specifically marked as
362
+ * invariant for a bit of extra protection.
363
+ *
364
+ * This does mean that `Brand` only works with types where an intersection is meaningful.
365
+ * These are the problematic types:
366
+ * - `any` will become `any` still because `any & T` is still `any`. This makes `Brand` useless.
367
+ * - `never` stays `never` because `never & T` is `never`. This makes `Brand` useless.
368
+ * - `unknown` becomes `Branded` because `unknown & T` is `T`. This is a problem because `unknown` can be any type, e.g. `number` but `Branded<unknown, BrandName>` is always an object.
369
+ *
370
+ * Unfortunately there aren't really good workarounds either.
371
+ */
372
+ export type Brand<BaseType, BrandName extends string> = BaseType & Branded<BrandName>;
373
+
374
+ /**
375
+ * An at a best effort level expands a type from something complex that shows up like
376
+ * `DeepPartial<{ x: { y: number } }>` in intellisense to `{ x?: { y?: number } }`.
377
+ * This is useful for when you want to see what a type looks like in a more human
378
+ * readable form.
379
+ *
380
+ * Using this type is a performance tradeoff, might increase the likelihood of
381
+ * circularities, and technically in some extremely niche cases changes the type behavior.
382
+ * ```@example
383
+ * // The implementation of this type is outside the scope of this example.
384
+ * // See UnionToIntersection.
385
+ * type UnionToIntersection<U> = (U extends unknown ? (arg: U) => void : never) extends (arg: infer I) => void ? I : never;
386
+ *
387
+ * type ObjectIntersection = UnionToIntersection<{ x: string } | { y: number }>;
388
+ * // ^ { x: string } & { y: number }
389
+ *
390
+ * type PrettyObjectIntersection = PrettifyType<ObjectIntersection>;
391
+ * // ^ { x: string, y: number }
392
+ *
393
+ * function example<T extends { someProp: number } | { anotherProp: string }>(t: T) {
394
+ * Object.assign(t, { a: "foo" }, { b: 2 }) satisfies ObjectIntersection
395
+ * Object.assign(t, { a: "foo" }, { b: 2 }) satisfies PrettyObjectIntersection
396
+ * // ^ Type 'T & { a: string; } & { b: number; }' does not satisfy the expected type '{ a: string; b: number; }'.
397
+ * // This is an example of changing type behavior. The first line is allowed but the second errors.
398
+ * // This type of situation will realistically never come up in real code because it's so contrived.
399
+ * // Note that this difference only appears when generic, specifically `T extends SomeConcreteObject | U`.
400
+ * // See https://github.com/microsoft/TypeScript/pull/60726 for some context.
401
+ * }
402
+ * ```
403
+ */
404
+ // Note(LukeAbby): This uses `AnyObject` as a constraint rather than in the body due to this circularity: https://tsplay.dev/NDpRRN
405
+ export type PrettifyType<T extends AnyObject> = T extends unknown
406
+ ? {
407
+ [K in keyof T]: T[K];
408
+ // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
409
+ } & unknown
410
+ : never;
411
+
412
+ /**
413
+ * Convert a union of the form `T1 | T2 | T3 | ...` into an intersection of the form `T1 & T2 & T3 & ...`.
414
+ *
415
+ * ### Implementation Details
416
+ *
417
+ * Breaking this type down into steps evaluation begins with the expression
418
+ * `U extends unknown ? ... : never`. Note that `U` is a "bare type parameter",
419
+ * that is written directly as opposed to being wrapped like `U[]`. Because of
420
+ * this the type is distributive.
421
+ *
422
+ * Distributivity means that `U extends unknown ? (arg: U) => void : never` turns the input
423
+ * of the form `T1 | T2 | T3 | ...` into `((arg: T1) => void) | ((arg: T2) => void) | ((arg: T3) => void)`.
424
+ * Let's call this new union `FunctionUnion`
425
+ *
426
+ * Finally `FunctionUnion extends (arg: infer I) => void ? I : never` is evaluated.
427
+ * This results in `T1 & T2 & T3 | ...` as promised... but why? Even with distributivity
428
+ * in play, normally `(T extends unknown ? F<T> : never) extends F<infer T> ? T : never`
429
+ * would just be a complex way of writing `T`.
430
+ *
431
+ * The complete answer is fairly deep and is unlikely to make sense unless you are
432
+ * already well versed in this area. In particular it lies in what happens when `F<T>`
433
+ * puts `T` into a contravariant position. In this case inferring `T` back out
434
+ * requires an intersection effectively because the covariant assignment rules
435
+ * are flipped.
436
+ *
437
+ * That explanation is unlikely to have helped much and so let's run through two
438
+ * examples.
439
+ *
440
+ * First, a refresher:
441
+ * ```ts
442
+ * function takesX(arg: { x: number }): number { ... }
443
+ * function takesY(arg: { y: string }): string { ... }
444
+ *
445
+ * let output = ...;
446
+ * if (Math.random() > 0.5) {
447
+ * output = takesX({ x: 1 });
448
+ * } else {
449
+ * output = takesY({ y: "example" });
450
+ * }
451
+ * ```
452
+ *
453
+ * What is the best type for `output` in this case? Of course, it'd be `number | string`.
454
+ *
455
+ * What about this example?
456
+ * ```ts
457
+ * function takesX(arg: { x: number }): number { ... }
458
+ * function takesY(arg: { y: string }): string { ... }
459
+ *
460
+ * let input = ...;
461
+ * if (Math.random() > 0.5) {
462
+ * takesX(input);
463
+ * } else {
464
+ * takesY(input);
465
+ * }
466
+ * ```
467
+ *
468
+ * What is the best type for `input` in this case? It might be tempting to say `{ x: number } | { y: string }`
469
+ * similarly to how `output` was `number | string`. But that's not quite right. The correct type for `input` is
470
+ * actually `{ x: number } & { y: string }`. The reason why this is the case is that it's unpredictable whether
471
+ * `takesX` or `takesY` will be called. This means that `input` must be able to used to call both functions.
472
+ *
473
+ * This is analogous to asking these two questions at the type level:
474
+ * ```ts
475
+ * type Functions = typeof takesX | typeof takesY;
476
+ * type Output = Functions extends (...args: any[]) => infer Output ? Output : never;
477
+ * // ^ number | string
478
+ * type Input = Functions extends (arg: infer Input) => any ? Input : never;
479
+ * // ^ { x: number } & { y: string }
480
+ * ```
481
+ *
482
+ * And if you reflect on the inciting code, `FunctionUnion extends (arg: infer I) => void ? I : never`
483
+ * you'll see that it's effectively doing the same thing.
484
+ *
485
+ * If you want to read more see TypeScript's handbook section on
486
+ * [Distributive Conditional Types](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types)
487
+ * for more information on distributivity. There is also a section on
488
+ * [Variance](https://www.typescriptlang.org/docs/handbook/2/generics.html#variance-annotations)
489
+ * in general but it unfortunately doesn't touch too much on specific details and
490
+ * the emergent behavior of variance like this.
491
+ */
492
+ export type UnionToIntersection<U> = (U extends unknown ? (arg: U) => void : never) extends (arg: infer I) => void
493
+ ? I
494
+ : never;
495
+
496
+ // Helper Types
497
+
498
+ /**
499
+ * Recursively sets keys of an object to optional. Used primarily for update methods.
500
+ *
501
+ * Note: This function is intended to work with plain objects. It takes any object only because
502
+ * otherwise it makes it more difficult to pass in interfaces.
503
+ *
504
+ * Its behavior is unspecified when run on a non-plain object.
505
+ */
506
+ // Allowing passing any `object` is done because it's more convenient for the end user.
507
+ // Note that `{}` should always be assignable to `DeepPartial<T>`.
508
+ export type DeepPartial<T extends object> = {
509
+ [K in keyof T]?: _DeepPartial<T[K]>;
510
+ };
511
+
512
+ // This type has to be factored out for distributivity.
513
+ type _DeepPartial<T> = T extends object ? (T extends AnyArray | AnyFunction | AnyConstructor ? T : DeepPartial<T>) : T;
514
+
515
+ /**
516
+ * Gets all possible keys of `T`. This is useful because if `T` is a union type
517
+ * it will get the properties of all types in the union. Otherwise it functions identically to `keyof T`.
518
+ */
519
+ export type AllKeysOf<T extends object> = T extends unknown ? keyof T : never;
520
+
521
+ /**
522
+ * Make all properties in `T` optional and explicitly allow `undefined`
523
+ *
524
+ * ### Picking the right helper type
525
+ * - Favor `NullishProps` whenever it is valid. Allowing both `null` and
526
+ * `undefined` is convenient for the end user and it is very common that
527
+ * wherever `undefined` is valid so is `null`. For some examples it is valid
528
+ * for `options.prop ??= "default"`, `options.prop ||= "default"`,
529
+ * `if (options.prop) { ... }`, `if (options.prop == null)`, or so on.
530
+ * - Use `IntentionalPartial` when an explicit `undefined` is problematic but
531
+ * leaving off the property entirely is fine. This primarily occurs when
532
+ * patterns like `options = { ...defaultOptions, ...options }`,
533
+ * `Object.assign({}, defaultOptions, options)`,
534
+ * `foundry.utils.mergeObject(defaultOptions, options)`, or so on.
535
+ *
536
+ * Note that {@link foundry.utils.mergeObject | `foundry.utils.mergeObject`}
537
+ * also expands the object. So once `ExpandsTo` exists you should also use
538
+ * that helper type.
539
+ *
540
+ * What these patterns have in common is that if `options` looks like
541
+ * `{ prop: undefined }` that will override whatever is in `defaultOptions`
542
+ * and may cause issues. Note that even if you see one of these patterns you
543
+ * also need to ensure that `undefined` would cause issues down the road
544
+ * before using `IntentionalPartial` as it could be an intended way of
545
+ * resetting a property.
546
+ * - Use `InexactPartial` when `null` is problematic but `undefined` is not.
547
+ * The most common time this shows up is with the pattern
548
+ * `exampleFunction({ prop = "foo" } = {}) { ... }`.
549
+ *
550
+ * @internal
551
+ */
552
+ export type InexactPartial<T extends object, K extends AllKeysOf<T> = AllKeysOf<T>> = PrettifyType<
553
+ {
554
+ [K2 in keyof T as Extract<K2, K>]?: T[K2] | undefined;
555
+ } & {
556
+ // Note(LukeAbby): This effectively inlines `Omit<T, K>` hoping for slightly better performance.
557
+ [K2 in keyof T as Exclude<K2, K>]: T[K2];
558
+ }
559
+ >;
560
+
561
+ /**
562
+ * Makes select properties in `T` optional and explicitly allows both `null` and
563
+ * `undefined` values.
564
+ *
565
+ * ### Picking the right helper type
566
+ * - Favor `NullishProps` whenever it is valid. Allowing both `null` and
567
+ * `undefined` is convenient for the end user and it is very common that
568
+ * wherever `undefined` is valid so is `null`. For some examples it is valid
569
+ * for `options.prop ??= "default"`, `options.prop ||= "default"`,
570
+ * `if (options.prop) { ... }`, `if (options.prop == null)`, or so on.
571
+ * - Use `IntentionalPartial` when an explicit `undefined` is problematic but
572
+ * leaving off the property entirely is fine. This primarily occurs when
573
+ * patterns like `options = { ...defaultOptions, ...options }`,
574
+ * `Object.assign({}, defaultOptions, options)`,
575
+ * `foundry.utils.mergeObject(defaultOptions, options)`, or so on.
576
+ *
577
+ * Note that {@link foundry.utils.mergeObject | `foundry.utils.mergeObject`}
578
+ * also expands the object. So once `ExpandsTo` exists you should also use
579
+ * that helper type.
580
+ *
581
+ * What these patterns have in common is that if `options` looks like
582
+ * `{ prop: undefined }` that will override whatever is in `defaultOptions`
583
+ * and may cause issues. Note that even if you see one of these patterns you
584
+ * also need to ensure that `undefined` would cause issues down the road
585
+ * before using `IntentionalPartial` as it could be an intended way of
586
+ * resetting a property.
587
+ * - Use `InexactPartial` when `null` is problematic but `undefined` is not.
588
+ * The most common time this shows up is with the pattern
589
+ * `exampleFunction({ prop = "foo" } = {}) { ... }`.
590
+ *
591
+ * @internal
592
+ */
593
+ export type NullishProps<T extends object, K extends AllKeysOf<T> = AllKeysOf<T>> = PrettifyType<
594
+ {
595
+ [K2 in keyof T as Extract<K2, K>]?: T[K2] | null | undefined;
596
+ } & {
597
+ // Note(LukeAbby): This effectively inlines `Omit<T, K>` hoping for slightly better performance.
598
+ [K2 in keyof T as Exclude<K2, K>]: T[K2];
599
+ }
600
+ >;
601
+
602
+ /**
603
+ * Expand an object that contains keys in dotted notation
604
+ * @internal
605
+ */
606
+ export type Expanded<O> = O extends AnyObject
607
+ ? {
608
+ [KO in keyof O as KO extends `${infer A}.${string}` ? A : KO]: KO extends `${string}.${infer B}`
609
+ ? Expanded<{ [EB in B]: O[KO] }>
610
+ : Expanded<O[KO]>;
611
+ }
612
+ : O;
613
+
614
+ /**
615
+ * Union type of the types of the values in `T`
616
+ * @internal
617
+ */
618
+ export type ValueOf<T extends object> = T extends ReadonlyArray<infer V> ? V : T[keyof T];
619
+
620
+ type OmitIndex<K extends PropertyKey> = string extends K
621
+ ? never
622
+ : number extends K
623
+ ? never
624
+ : symbol extends K
625
+ ? never
626
+ : K;
627
+
628
+ /**
629
+ * Gets the keys of `T` but excluding index signatures unlike `keyof T`. For example `Record<string, any> & { foo: number }` will produce `string` with `keyof` but `foo` with `ConcreteKeys`.
630
+ */
631
+ export type ConcreteKeys<T> = [T] extends [never]
632
+ ? never
633
+ : keyof {
634
+ [K in keyof T as OmitIndex<K>]: never;
635
+ };
636
+
637
+ /**
638
+ * Removes all index signatures from an object. Use this instead of `[K in keyof ConcreteKeys<T>]` to preserve modifiers e.g. readonly, or optional.
639
+ */
640
+ // NOTE(LukeAbby): It may seem easier to write `Pick<T, ConcreteKeys<T>>` but this stops it from being a homomorphic mapped type and regresses its power when given a generic type parameter or `this`.
641
+ // See: https://www.typescriptlang.org/play/?#code/KYDwDg9gTgLgBDAnmYcDCEB2BjKwbADSwiAzgDwAqAfHALxwDWJEAZnAN4BQccA2oTgBLTExbtKcAIak4pGFBEBzOKAKYAJrMEB+OJmAA3YFDgAufQFcAtgCMTqkOq1xd+ow4ulEdiABtHZ204PQNjUwtCAF0LMJMAbi4AX0SuJBQ4ACVgawhjAElNUABlISVMKRhLPAoaejgABSFsRioAGnQsXHwiElrqalTsPxlZABFKqQBZCA1gP3Ji7AALHKlabl454ak8OFy5vwts3IKikFLyyurgCiXV63Xkri4d0lliy1sZw8WVtcCwE0sg4cCUQJMzQaUAgYAsUkwiHi-EIXgUyhiVjsDiStDUQJcExg01m8z+D3WnB4+3wy1mAAoAJRU3i8AD0bLglGWQlkYBhKCgiDkdMsfg0jl58FslngGggt0wAHIYAA6am8GA80iqg7zVXggyKbDQ2GpVkIbW60l+VVSWzYRK8JLJIA
642
+ export type RemoveIndexSignatures<T extends object> = {
643
+ [K in keyof T as OmitIndex<K>]: T[K];
644
+ };
645
+
646
+ /**
647
+ * Transforms a string to lowercase and the first character to uppercase.
648
+ * @internal
649
+ */
650
+ export type Titlecase<S extends string> = S extends `${infer A} ${infer B}`
651
+ ? `${Titlecase<A>} ${Titlecase<B>}`
652
+ : Capitalize<Lowercase<S>>;
653
+
654
+ /**
655
+ * Deeply merge two types. If either of the given types is not an object then `U`
656
+ * simply overwrites `T`.
657
+ *
658
+ * Nested properties of type `object` are merged recursively unless the property
659
+ * in `U` is an `Array`.
660
+ *
661
+ * @typeParam T - The base type that `U` will be merged into.
662
+ * @typeParam U - The type that will be merged into `T`.
663
+ */
664
+ export type Merge<T, U> =
665
+ IsObject<U> extends true
666
+ ? IsObject<T> extends true
667
+ ? SimpleMerge<
668
+ T,
669
+ {
670
+ [K in keyof U]: T extends { readonly [_ in K]?: infer V } ? Merge<V, U[K]> : U[K];
671
+ }
672
+ >
673
+ : U
674
+ : U;
675
+
676
+ /**
677
+ * Returns whether the type is a plain object. Excludes functions, arrays, and constructors while still being friendly to interfaces.
678
+ *
679
+ * @example
680
+ * ```ts
681
+ * interface ObjectInterface {
682
+ * prop: number;
683
+ * }
684
+ *
685
+ * type Interface = IsObject<ObjectInterface>; // true
686
+ * type Object = IsObject<{ prop: number }>; // true
687
+ * type Array = IsObject<number[]>; // false
688
+ * type Function = IsObject<() => void>; // false
689
+ *
690
+ * // By comparison, simply comparing against `Record<string, unknown>` fails.
691
+ * type RecordFails = Interface extends Record<string, unknown> ? true : false; // false
692
+ * ```
693
+ */
694
+ export type IsObject<T> = T extends object ? (T extends AnyArray | AnyFunction | AnyConstructor ? false : true) : false;
695
+
696
+ /**
697
+ * A simple, non-recursive merge type.
698
+ * @typeParam Target - the target type to merge into
699
+ * @typeParam Override - the type whose properties override the ones in Target
700
+ */
701
+ export type SimpleMerge<Target, Override> = Omit<Target, keyof Override> & Override;
702
+
703
+ /**
704
+ * Makes the given keys `K` of the type `T` required
705
+ */
706
+ export type RequiredProps<T extends object, K extends AllKeysOf<T>> = Required<Pick<T, K>> & Omit<T, K>;
707
+
708
+ export type Mixin<MixinClass extends AnyConcreteConstructor, BaseClass extends AnyConstructor> = MixinClass & BaseClass;
709
+
710
+ interface GetDataConfigOptions<T> {
711
+ partial: Partial<T> & Record<string, unknown>;
712
+ exact: T;
713
+ object: object;
714
+ }
715
+
716
+ type GetDataConfigOption = GetDataConfig extends {
717
+ mode: infer Mode extends keyof GetDataConfigOptions<unknown>;
718
+ }
719
+ ? Mode
720
+ : "object";
721
+
722
+ export type GetDataReturnType<T extends object> = GetDataConfigOptions<T>[GetDataConfigOption];
723
+
724
+ /**
725
+ * Replaces the type `{}` with `Record<string, never>` by default which is
726
+ * usually a better representation of an empty object. The type `{}` actually
727
+ * allows any type be assigned to it except for `null` and `undefined`.
728
+ *
729
+ * The theory behind this is that all non-nullish types allow
730
+ * you to access any property on them without erroring. Primitive types like
731
+ * `number` will not store the property but it still will not error to simply
732
+ * try to get and set properties.
733
+ *
734
+ * The type `{}` can appear for example after operations like `Omit` if it
735
+ * removes all properties rom an object, because an empty interface was given,
736
+ * or so on.
737
+ *
738
+ * @example
739
+ * ```ts
740
+ * type ObjectArray<T extends Record<string, unknown>> = T[];
741
+ *
742
+ * // As you would hope a string can't be assigned in a union or not. It errors with:
743
+ * // "type 'string' is not assignable to type 'Record<string, unknown>'."
744
+ * type UnionErrors = ObjectArray<string | { x: number }>;
745
+ *
746
+ * // However, this works.
747
+ * type EmptyObjectArray = ObjectArray<{}>;
748
+ *
749
+ * // But it allows likely unsound behavior like this:
750
+ * const emptyObject: EmptyObjectArray = [1, "foo", () => 3];
751
+ *
752
+ * // So it may be better to define `ObjectArray` like so:
753
+ * type ObjectArray<T extends Record<string, unknown>> = HandleEmptyObject<T>[];
754
+ *
755
+ * // If it were, then this line would error appropriately!
756
+ * const emptyObject: EmptyObjectArray = [1, "foo", () => 3];
757
+ * ```
758
+ */
759
+ export type HandleEmptyObject<O, D = EmptyObject> =
760
+ // Note(LukeAbby): This uses a strict equality test to differentiate types like `{ onlyOptional?: true }`
761
+ // and `object` from `{}`. More naive tests like `[{}] extends [O] ? ... : ...` fails these cases
762
+ // due to particular unsoundness rules around `{}`.
763
+ //
764
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
765
+ (<T>() => T extends {} ? true : false) extends <T>() => T extends O ? true : false ? D : O;
766
+
767
+ /**
768
+ * This type allows any plain objects. In other words it disallows functions
769
+ * and arrays.
770
+ *
771
+ * Use this type instead of:
772
+ * - `object`/`Record<any, any>` - This allows functions, classes, and arrays.
773
+ * - `{}` - This type allows anything besides `null` and `undefined`.
774
+ * - `Record<string, unknown>` - This is the appropriate type for any mutable object but doesn't allow readonly objects.
775
+ */
776
+ // This type is not meant to be extended and it has to use an indexed type.
777
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
778
+ export type AnyObject = {
779
+ readonly [K: string]: unknown;
780
+ };
781
+
782
+ /**
783
+ * This type allows mutable plain objects. This means readonly objects cannot be
784
+ * assigned.
785
+ *
786
+ * Use this type instead of:
787
+ * - `object` - This allows functions and arrays.
788
+ * - `Record<string, any>`/`{}` - These allows anything besides `null` and `undefined`.
789
+ * - `Record<string, unknown>` - These types are equivalent but `AnyMutableObject` is preferred for explicitness.
790
+ */
791
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
792
+ export type AnyMutableObject = {
793
+ [K: string]: unknown;
794
+ };
795
+
796
+ /**
797
+ * Use this type to allow any array. This allows readonly arrays which is
798
+ * generally what you want. If you need a mutable array use the
799
+ * {@link MutableArray | `MutableArray`} type instead of the builtin `T[]` or
800
+ * `Array` types. This allows us to be more explicit about intent.
801
+ *
802
+ * Consider being more specific if possible. You should generally try to use a
803
+ * concrete array with a union or add a type parameter first.
804
+ *
805
+ * Use this instead of:
806
+ * - `any[]` - When elements of this array are accessed you get `any` which is not safe.
807
+ * - `unknown[]` - This is the appropriate type for any mutable array but doesn't allow readonly arrays.
808
+ */
809
+ export type AnyArray = readonly unknown[];
810
+
811
+ /**
812
+ * Use this type to allow a mutable array of type `T`. Only use this if the
813
+ * array can be soundly mutated. Otherwise you should be using
814
+ * `readonly T[]` or {@link ReadonlyArray | `ReadonlyArray`}
815
+ */
816
+ export type MutableArray<T> = Array<T>;
817
+
818
+ /**
819
+ * Use this type to allow any function. Notably since this allows any function
820
+ * it is difficult to call the function in a safe way. This means its uses are
821
+ * mostly niche and it should be avoided.
822
+ *
823
+ * Make sure you have a good reason to use this type. It is almost always better
824
+ * to use a more specific function type. Please consider leaving a comment about
825
+ * why this type is necessary.
826
+ *
827
+ * Use this instead of:
828
+ * - `Function` - This refers to the fundamental `Function` object in JS. It allows classes.
829
+ * - `(...args: any[]) => any` - If someone explicitly accesses the parameters or uses the return value you get `any` which is not safe.
830
+ * - `(...args: unknown[]) => unknown` - This allows obviously unsound calls like `fn(1, "foo")` because it indicates it can take any arguments.
831
+ */
832
+ export type AnyFunction = (...args: never) => unknown;
833
+
834
+ /**
835
+ * Use this type to allow any class, abstract class, or class-like constructor.
836
+ *
837
+ * See {@link AnyConcreteConstructor | `AnyConcreteConstructor`} if you cannot
838
+ * allow abstract classes. Please also consider writing a comment
839
+ * explaining why {@link AnyConcreteConstructor | `AnyConcreteConstructor`} is
840
+ * necessary.
841
+ *
842
+ * @example
843
+ * ```ts
844
+ * const concrete: AnyConstructor = class Concrete { ... }
845
+ * const abstract: AnyConstructor = abstract class Abstract { ... }
846
+ *
847
+ * // `Date` is not actually a class but it can be used as a constructor.
848
+ * const classLike: AnyConstructor = Date;
849
+ * ```
850
+ */
851
+ export type AnyConstructor = abstract new (...args: never) => unknown;
852
+
853
+ /**
854
+ * Use this type to allow any class or class-like constructor but disallow
855
+ * class-like constructors.
856
+ *
857
+ * Use this type only when abstract classes would be problematic such as the
858
+ * base type of a mixin. Please consider writing a comment explaining why.
859
+ * See {@link AnyConstructor | `AnyConstructor`} to also allow abstract classes.
860
+ *
861
+ * @example
862
+ * ```ts
863
+ * const concrete: AnyConcreteConstructor = class Concrete { ... }
864
+ *
865
+ * // `Date` is not actually a class but it can be used as a constructor.
866
+ * const classLike: AnyConcreteConstructor = Date;
867
+ *
868
+ * // This next line errors:
869
+ * const abstract: AnyConcreteConstructor = abstract class Abstract { ... }
870
+ * ```
871
+ */
872
+ export type AnyConcreteConstructor = new (...args: never) => unknown;
873
+
874
+ /**
875
+ * This type is equivalent to `Promise<T>` but exists to give an explicit signal
876
+ * that this is not a mistake. When Foundry accepts an asynchronous callback the
877
+ * vast majority of the time it is best to use {@link MaybePromise | `MaybePromise`}.
878
+ *
879
+ * By doing it this way the maximum flexibility is given to the definer of the
880
+ * callback. This is okay because typically asynchronous callbacks are simply
881
+ * awaited, meaning that there's no noticeable difference between a `Promise`
882
+ * and {@link MaybePromise | `MaybePromise`}. Even functions like
883
+ * {@link Promise.allSettled | `Promise.allSettled`} function correctly
884
+ * with {@link MaybePromise | `MaybePromise`}.
885
+ *
886
+ * Do not use this type or {@link MaybePromise | `MaybePromise`} for the return
887
+ * type of asynchronous methods on classes. For example for
888
+ * {@link foundry.abstract.Document._preCreate | `Document#_preCreate`} the typing
889
+ * should be `Promise<void>` and not this type. In theory we could use
890
+ * {@link MaybePromise | `MaybePromise`} in this context as well but this seems
891
+ * more likely to be confusing than to be helpful.
892
+ *
893
+ * Use this type only in the rare case where a callback's return type must be a
894
+ * `Promise`, for example if `promise.then` or `promise.catch` is explicitly
895
+ * called. Please also writing a comment explaining why
896
+ * {@link MaybePromise | `MaybePromise`} is problematic in this context.
897
+ */
898
+ export type MustBePromise<T> = Promise<T>;
899
+
900
+ /**
901
+ * Use when a type may be either a promise or not. This is most useful in
902
+ * asynchronous callbacks where in most cases it's sound to provide a synchronous
903
+ * callback instead.
904
+ *
905
+ * If it is not sound to provide a non-Promise for whatever reason, see
906
+ * {@link MustBePromise | `MustBePromise`} to declare this more explicitly than simply writing
907
+ * `Promise<T>`.
908
+ *
909
+ * This should generally not be used in asynchronous methods. For example in
910
+ * {@link foundry.abstract.Document._preCreate | `Document#_preCreate`} the typing
911
+ * is `Promise<void>` because it's declared as an async method. Overriding an
912
+ * asynchronous method with a synchronous method is more confusing than
913
+ * helpful.
914
+ */
915
+ export type MaybePromise<T> = T | Promise<T>;
916
+
917
+ /**
918
+ * Use this to allow any type besides `null` or `undefined`.
919
+ *
920
+ * This type is equivalent to the type `{}`. It exists to give this type a
921
+ * better name. `{}` is not a type representing an empty object. In reality it
922
+ * allows assigning any type besides `null` or `undefined`. This is frustrating
923
+ * but it seems the theory is supposed to be that all types except for `null`
924
+ * and `undefined` will return `undefined` for any property accessed on them.
925
+ *
926
+ * Even primitives like `number` will not error when you get or even set a
927
+ * property on them, although they will not preserve the property. Since the
928
+ * only type that cannot be indexed is `null` or `undefined` this is the chosen
929
+ * semantics of `{}` in TypeScript.
930
+ */
931
+ // This type is not meant to be extended and it's meant to be the explicit version of what the type `{}` does, i.e. allow any type besides `null` or `undefined`.
932
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions, @typescript-eslint/no-empty-object-type
933
+ export type NonNullish = {};
934
+
935
+ /**
936
+ * This is the closest approximation to a type representing an empty object.
937
+ *
938
+ * Use instead of `{}` when you want to represent an empty object. `{}` actually
939
+ * allows any type that is not `null` or `undefined`. see
940
+ * {@link NonNullish | `NonNullish`} if you want that behavior.
941
+ */
942
+ // It would be unsound to merge into so an interface is not used.
943
+ export type EmptyObject = Record<string, never>;
944
+
945
+ declare const empty: unique symbol;
946
+
947
+ /**
948
+ * This helper type helps emulate index signatures for types with incompatible concrete keys.
949
+ *
950
+ * For example the type `{ foo: number; [K: string]: string }` is not allowed because the index signature is incompatible with the concrete key `foo`.
951
+ * It may seem like tricks like `{ foo: number; } & { [K: string]: string }` work but this defers the error to the caller.
952
+ *
953
+ * @example
954
+ * ```typescript
955
+ * type NaiveType = { foo: number; [K: string]: boolean };
956
+ * // ^ Property 'foo' of type 'number' is not assignable to 'string' index type 'boolean'.
957
+ *
958
+ * type NaiveIntersection = { foo: number } & { [K: string]: string };
959
+ *
960
+ * function usesIntersection(intersection: NaiveIntersection) { ... }
961
+ *
962
+ * usesIntersection({ foo: 1, x: true });
963
+ * // ^ Argument of type '{ foo: number; }' is not assignable to parameter of type 'NaiveIntersection'.
964
+ * // Type '{ foo: number; }' is not assignable to type '{ [K: string]: boolean; }'.
965
+ * // Property 'foo' is incompatible with index signature.
966
+ * // Type 'number' is not assignable to type 'boolean'.
967
+ *
968
+ * function usesCorrectly<T extends AnyObject>(withIndex: ShapeWithIndexSignature<T, { foo: number }, string, boolean>) { ... }
969
+ *
970
+ * usesCorrectly({ foo: 1, x: true });
971
+ * ```
972
+ */
973
+ // Note: If https://github.com/microsoft/TypeScript/issues/17867 or https://github.com/microsoft/TypeScript/issues/43826 (depending on implementation) is implemented it's likely this type can be expressed in a better way.
974
+ export type ShapeWithIndexSignature<
975
+ T extends AnyObject,
976
+ // Uses `extends object` to allow interfaces and if useful other objects.
977
+ PrimaryShape extends object,
978
+ IndexSignature extends PropertyKey,
979
+ IndexType,
980
+ > = PrimaryShape & {
981
+ readonly [K in keyof T & IndexSignature]: K extends keyof PrimaryShape ? PrimaryShape[K] : IndexType;
982
+ };
983
+
984
+ /**
985
+ * Defer is a utility type that allows you to defer the evaluation of a type.
986
+ * The use cases for this are extremely advanced. In essence they have to do with breaking cycles in evaluation.
987
+ */
988
+ export type Defer<T> = [T][T extends any ? 0 : never];
989
+
990
+ export type MustBeValidUuid<Uuid extends string, Type extends Document.Type = Document.Type> = _MustBeValidUuid<
991
+ Uuid,
992
+ Uuid,
993
+ Type
994
+ >;
995
+
996
+ /**
997
+ * Quotes a string for human readability. This is useful for error messages.
998
+ *
999
+ * @example
1000
+ * ```ts
1001
+ * type Quote1 = Quote<"foo">;
1002
+ * // ^ "'foo'"
1003
+ *
1004
+ * type Quote2 = Quote<"can't">;
1005
+ * // ^ "'can\\'t'"
1006
+ * ```
1007
+ */
1008
+ export type Quote<T extends string> = T extends `${string}'${string}` ? `'${Escape<T>}'` : `'${T}'`;
1009
+
1010
+ type Escape<T extends string> = T extends `${infer Prefix}'${infer Suffix}` ? `${Prefix}\\'${Escape<Suffix>}` : T;
1011
+
1012
+ declare class InvalidUuid<OriginalUuid extends string> {
1013
+ #invalidUuid: true;
1014
+
1015
+ message: `The UUID ${Quote<OriginalUuid>} is invalid .`;
1016
+ }
1017
+
1018
+ type _MustBeValidUuid<
1019
+ Uuid extends string,
1020
+ OriginalUuid extends string,
1021
+ Type extends Document.Type,
1022
+ > = Uuid extends `${string}.${string}.${infer Rest}`
1023
+ ? _MustBeValidUuid<Rest, OriginalUuid, Type>
1024
+ : Uuid extends `${string}.${string}`
1025
+ ? Uuid extends `${Type}.${string}`
1026
+ ? OriginalUuid
1027
+ : InvalidUuid<OriginalUuid>
1028
+ : `${Type}.${string}` | `${string}.${string}.${Type}.${string}`;
1029
+
1030
+ /**
1031
+ * Drops the first element of an array
1032
+ */
1033
+ type DropFirst<T extends AnyArray> = T extends [infer _1, ...infer V] ? V : T;
1034
+
1035
+ /**
1036
+ * This type is used when you want to use `unknown` in a union. This works because while `T | unknown`
1037
+ * will reduce to `unknown`. However by comparison the only way that `T | LazyUnknown` can reduce is
1038
+ * if there's
1039
+ *
1040
+ * This makes it the ideal type to accept any input in some situations, mostly for documenting types
1041
+ * where anything is acceptable but certain ones are more notable. For example `number | LazyUnknown`
1042
+ * would still accept anything but appear as `number | {} | null | undefined` in intellisense, due
1043
+ * to the inlining of the composite parts of `LazyUnknown`.
1044
+ *
1045
+ * The type `{}` isn't actually the type for an empty object. It allows anything except
1046
+ * `null`/`undefined` which is why `{} | null | undefined` allows anything to be assigned to it.
1047
+ * See {@link NonNullish | `NonNullish`} for a further explanation on why `{}` allows anything
1048
+ * besides `null`/`undefined`.
1049
+ */
1050
+ export type LazyUnknown = NonNullish | null | undefined;
1051
+
1052
+ /**
1053
+ * `Coalesce` is useful to provide defaults. For example if you have the function:
1054
+ * ```js
1055
+ * function toString(item="default") {
1056
+ * return `${item}`;
1057
+ * }
1058
+ * ```
1059
+ *
1060
+ * Then the most appropriate type might be:
1061
+ * ```ts
1062
+ * declare function toString<
1063
+ * Item extends string | number | undefined = undefined
1064
+ * >(item?: Item): `${Coalesce<Item, "default">}`
1065
+ *
1066
+ * const itemUnset = toString();
1067
+ * // ^ "default"
1068
+ *
1069
+ * const itemUndefined = tgoString(undefined);
1070
+ * // ^ "default"
1071
+ * ```
1072
+ *
1073
+ * This is because generic parameter defaults and function parameters behave differently. A function
1074
+ * default is used whenever `undefined` would otherwise be the value, either explicitly or implicitly
1075
+ * i.e. both `doubles()` and `doubles(undefined)` would use the default of `"default"`. However a generic'
1076
+ * defaults only shows up when it's not used at all. The behavior with an explicit `undefined` has
1077
+ * two cases to explain:
1078
+ *
1079
+ * ```ts
1080
+ * declare function toString1<Item extends string | number = "foo">(item?: Item): void;
1081
+ *
1082
+ * toString1(undefined);
1083
+ * // `Item` will infer as `string | number` because `undefined` isn't assignable to the constraint of `Item`.
1084
+ *
1085
+ * declare function toString2<Item extends string | number | undefined = "foo">(item?: Item): void;
1086
+ *
1087
+ * toString2(undefined);
1088
+ * // `Item` will infer as `undefined` not `"foo"` because the generic has something to infer from.
1089
+ * ```
1090
+ */
1091
+ export type Coalesce<T, D, CoalesceType = undefined> = T extends CoalesceType ? D : T;
1092
+
1093
+ /**
1094
+ * Coalesces specifically `null | undefined`. Behaves like `??` does at runtime.
1095
+ * See {@link Coalesce | `Coalesce`}.
1096
+ */
1097
+ export type NullishCoalesce<T, D> = T extends null | undefined ? D : T;
1098
+
1099
+ interface EarlierHook {
1100
+ none: never;
1101
+ init: "none";
1102
+ i18nInit: "none" | "init";
1103
+ setup: "none" | "init" | "i18nInit";
1104
+ ready: "none" | "init" | "i18nInit" | "setup";
1105
+ }
1106
+
1107
+ /**
1108
+ * A hook that's valid to use in {@link AssumeHookRan | `AssumeHookRan`}
1109
+ */
1110
+ export type InitializationHook = keyof EarlierHook;
1111
+
1112
+ /**
1113
+ * All hooks ran so far.
1114
+ *
1115
+ * @example
1116
+ * ```ts
1117
+ * HooksRan<never>; // never
1118
+ * HooksRan<"none">; // "none"
1119
+ * HooksRan<"init">; // "none" | "init"
1120
+ * HooksRan<"i18nInit">; // "none" | "init" | "i18nInit"
1121
+ * HooksRan<"setup">; // "none" | "init" | "i18nInit" | "setup"
1122
+ * HooksRan<"setup">; // "none" | "init" | "i18nInit" | "setup" | "ready"
1123
+ * ```
1124
+ */
1125
+ export type HooksRan<T extends InitializationHook> = EarlierHook[T] | T;
1126
+ type ValidHooksRan = Extract<keyof AssumeHookRan, InitializationHook>;
1127
+
1128
+ /**
1129
+ * Various things within Foundry are only initialized after a certain hook is ran.
1130
+ * `InitializedOn` is useful to help model this pattern.
1131
+ */
1132
+ export type InitializedOn<
1133
+ InitializedTo,
1134
+ InitializedOnHook extends InitializationHook,
1135
+ BeforeInitialization = InitializedTo | undefined,
1136
+ > = Extract<HooksRan<ValidHooksRan>, InitializedOnHook> extends never ? InitializedTo : BeforeInitialization;
1137
+
1138
+ /**
1139
+ * Returns the inputted type. This may seem like a useless type but it exists due to limitations
1140
+ * with the syntax of TypeScript interfaces. For example it's a syntax error to write
1141
+ * `interface Example extends typeof SomeClass {}` but `typeof SomeClass` is a reasonable base type
1142
+ * so to work around this you can write `interface Example extends Identity<typeof SomeClass> {}`
1143
+ */
1144
+ export type Identity<T extends object> = T;
1145
+
1146
+ /**
1147
+ * ### Usage
1148
+ *
1149
+ * Note: See "Background" for an explanation of what a "Discriminated Union" is.
1150
+ *
1151
+ * Use `DiscriminatedUnion` when you want to turn a regular union into a discriminated union. The form
1152
+ * this helper type chooses is
1153
+ * `{ prop1: number; readonly prop2?: never } | { readonly prop1?: never; prop2: string }` as this
1154
+ * is the strictest form of a discriminated union. `readonly prop1?: never` is very similar to
1155
+ * `prop1?: undefined` but `never` is used because with
1156
+ * [`exactOptionalPropertyTypes`](https://www.typescriptlang.org/tsconfig/exactOptionalPropertyTypes.html)
1157
+ * there is an actual difference and `readonly` is there because it prevents erroneous mutation.
1158
+ *
1159
+ * Please note that this type is unsound when you don't know for sure the union can't have
1160
+ * excess properties that interfere with other constituents. For a basic example of this unsoundness:
1161
+ * ```ts
1162
+ * function selectRandom<T, U>(array1: T, array2: U): DiscrimatedUnion<T | U> {
1163
+ * return (Math.random() > 0.5 ? array1 : array2) as DiscrimatedUnion<T | U>;
1164
+ * }
1165
+ *
1166
+ * const obj1 = { prop1: "foo" };
1167
+ * const obj2: { prop2: number } = { prop1: 1, prop2: "bar" };
1168
+ *
1169
+ * const discriminatedUnion = selectRandom(obj1, obj2)
1170
+ *
1171
+ * // If `selectRandom` returned `T | U` then `discriminatedUnion.prop1` would error.
1172
+ * // However because of unsoundly using `DiscrimatedUnion` it doesn't.
1173
+ * const prop1 = discriminatedUnion.prop1;
1174
+ * // ^ `string | undefined`.
1175
+ *
1176
+ * console.log(prop1 !== undefined ? prop1.length : 0);
1177
+ * // ^ Runtime error the 50% of the time that `prop1` is actually `1` at runtime
1178
+ * ```
1179
+ *
1180
+ * ### Background
1181
+ *
1182
+ * A common unintuitive behavior of unions in TypeScript is that if a property only exists on some
1183
+ * members of the union access is not allowed:
1184
+ * ```typescript
1185
+ * const member1 = { prop1: "foo" };
1186
+ * const member2 = { prop2: 1 };
1187
+ * const union = Math.random() > 0.5 ? member1 : member2;
1188
+ * // ^ { prop1: string; } | { prop2: number; }
1189
+ *
1190
+ * const prop1 = union.prop1;
1191
+ * ```
1192
+ *
1193
+ * This snippet errors with:
1194
+ * ```
1195
+ * Property 'prop1' does not exist on type '{ prop1: number; } | { prop2: number; }'.
1196
+ * Property 'prop1' does not exist on type '{ prop2: number; }'.`
1197
+ * ```
1198
+ *
1199
+ * This error is not very good at explaining why the result can't simply be `number | undefined` but
1200
+ * it can't simply be relaxed. To understand why you need to know that excess properties can always
1201
+ * be assigned to an object. To demonstrate:
1202
+ * ```ts
1203
+ * function takesObj(obj: { prop1: number }) { ... }
1204
+ *
1205
+ * // You may think excess properties aren't allowed because when you try to write code like this,
1206
+ * // it errors.
1207
+ * takesObj({ prop1: 1, prop2: "foo" });
1208
+ * // ^ Object literal may only specify known properties, but 'prop2' does not exist in type '{ prop1: number; }'. Did you mean to write 'prop1'?
1209
+ *
1210
+ * // However this is more of a "lint" than a hard error.
1211
+ * const obj = { prop1: 1, prop2: "foo" };
1212
+ * takesObj(obj); // No error
1213
+ * ```
1214
+ *
1215
+ * This means that the type of `union.prop1` would have to be `unknown` at best because at runtime
1216
+ * there could be any excess properties of any type.
1217
+ *
1218
+ * ### Discriminated Unions
1219
+ *
1220
+ * Discriminated unions are a way to get around this issue. There's several possible ways to express
1221
+ * discriminated unions but the most common version is
1222
+ * `{ prop1: number; prop2?: undefined } | { prop1?: undefined; prop1: number }`. The key idea is to
1223
+ * put a property that
1224
+ *
1225
+ * In fact TypeScript will automatically create a discriminated union in some cases. For example if
1226
+ * you simplify the snippet above:
1227
+ * ```typescript
1228
+ * const discriminatedUnion = Math.random() > 0.5 ? { prop1: 1 } : { prop2: 2 };
1229
+ * // ^ { prop1: number; prop2?: undefined } | { prop2: number; }
1230
+ *
1231
+ * const prop1 = discriminatedUnion.prop1;
1232
+ * // ^ number | undefined
1233
+ * ```
1234
+ *
1235
+ * You'll see TypeScript now has enough information to give `discriminatedUnion` a better type than
1236
+ * `union` had which now makes `discriminatedUnion.prop1` work.
1237
+ *
1238
+ * See:
1239
+ *
1240
+ * {@link https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions}
1241
+ *
1242
+ * {@link https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes-func.html#discriminated-unions}
1243
+ */
1244
+ export type DiscriminatedUnion<U extends object> = _DiscriminatedUnion<U, AllKeysOf<U>>;
1245
+
1246
+ type _DiscriminatedUnion<U extends object, AllKeys extends AllKeysOf<U>> = U extends unknown
1247
+ ? {
1248
+ [K in keyof U]: U[K];
1249
+ } & {
1250
+ readonly [K in Exclude<AllKeys, keyof U>]?: never;
1251
+ }
1252
+ : never;
1253
+
1254
+ /**
1255
+ * Picks keys where the value extends `Value`
1256
+ *
1257
+ * @example
1258
+ * ```typescript
1259
+ * type Picked = PickValue<{ type: "coordinates"; x: 123; y: 456; }, number>;
1260
+ * // ^ { x: 123; y: 456 }
1261
+ * ```
1262
+ */
1263
+ export type PickValue<T extends object, Value> = {
1264
+ [K in keyof T as T[K] extends Value ? K : never]: T[K];
1265
+ };
1266
+
1267
+ /**
1268
+ * Represnts a valid JSON value.
1269
+ */
1270
+ export type JSONValue =
1271
+ | {
1272
+ readonly [K: string]: JSONValue;
1273
+ }
1274
+ | readonly JSONValue[]
1275
+ | number
1276
+ | string
1277
+ | boolean
1278
+ | null
1279
+ | undefined;