phoria2 0.0.0-stage → 1.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +132 -2
  3. package/dist/charts.js +1787 -0
  4. package/dist/charts.js.map +1 -0
  5. package/dist/core.js +5382 -0
  6. package/dist/core.js.map +1 -0
  7. package/dist/explain.js +52 -0
  8. package/dist/explain.js.map +1 -0
  9. package/dist/gltf.js +470 -0
  10. package/dist/gltf.js.map +1 -0
  11. package/dist/hdr.js +51 -0
  12. package/dist/hdr.js.map +1 -0
  13. package/dist/particles.js +297 -0
  14. package/dist/particles.js.map +1 -0
  15. package/dist/passes.js +218 -0
  16. package/dist/passes.js.map +1 -0
  17. package/dist/phoria2.js +1 -0
  18. package/dist/picking.js +170 -0
  19. package/dist/picking.js.map +1 -0
  20. package/dist/snapshot.js +22 -0
  21. package/dist/snapshot.js.map +1 -0
  22. package/dist/tooltip.js +55 -0
  23. package/dist/tooltip.js.map +1 -0
  24. package/dist/types/OrbitControl.d.ts +119 -0
  25. package/dist/types/Raycaster.d.ts +74 -0
  26. package/dist/types/View.d.ts +254 -0
  27. package/dist/types/charts/Chart.d.ts +55 -0
  28. package/dist/types/charts/axes.d.ts +29 -0
  29. package/dist/types/charts/index.d.ts +10 -0
  30. package/dist/types/charts/legend.d.ts +15 -0
  31. package/dist/types/charts/marks.d.ts +74 -0
  32. package/dist/types/charts/network.d.ts +9 -0
  33. package/dist/types/charts/scales.d.ts +107 -0
  34. package/dist/types/charts/spec.d.ts +62 -0
  35. package/dist/types/charts/style.d.ts +1 -0
  36. package/dist/types/describe.d.ts +27 -0
  37. package/dist/types/explain.d.ts +38 -0
  38. package/dist/types/frame.d.ts +277 -0
  39. package/dist/types/geometry/Geometry.d.ts +91 -0
  40. package/dist/types/geometry/fromPolygons.d.ts +52 -0
  41. package/dist/types/geometry/generators.d.ts +192 -0
  42. package/dist/types/gltf/Animation.d.ts +51 -0
  43. package/dist/types/gltf/index.d.ts +6 -0
  44. package/dist/types/gltf/load.d.ts +54 -0
  45. package/dist/types/hdr.d.ts +8 -0
  46. package/dist/types/index.d.ts +48 -0
  47. package/dist/types/irradiance.d.ts +10 -0
  48. package/dist/types/labelLayout.d.ts +60 -0
  49. package/dist/types/labels.d.ts +50 -0
  50. package/dist/types/material/Material.d.ts +208 -0
  51. package/dist/types/material/Texture.d.ts +87 -0
  52. package/dist/types/math/mat3.d.ts +8 -0
  53. package/dist/types/math/mat4.d.ts +39 -0
  54. package/dist/types/math/quat.d.ts +18 -0
  55. package/dist/types/math/vec2.d.ts +10 -0
  56. package/dist/types/math/vec3.d.ts +34 -0
  57. package/dist/types/math/vec4.d.ts +10 -0
  58. package/dist/types/math.d.ts +8 -0
  59. package/dist/types/particles/Body.d.ts +46 -0
  60. package/dist/types/particles/Emitter.d.ts +145 -0
  61. package/dist/types/particles/index.d.ts +10 -0
  62. package/dist/types/presets.d.ts +44 -0
  63. package/dist/types/registry.d.ts +10 -0
  64. package/dist/types/resolve.d.ts +17 -0
  65. package/dist/types/scene/Node.d.ts +236 -0
  66. package/dist/types/scene/Scene.d.ts +75 -0
  67. package/dist/types/scene/cameras.d.ts +78 -0
  68. package/dist/types/scene/drawables.d.ts +290 -0
  69. package/dist/types/scene/lights.d.ts +151 -0
  70. package/dist/types/shadow.d.ts +30 -0
  71. package/dist/types/snapshot.d.ts +29 -0
  72. package/dist/types/tooltip.d.ts +17 -0
  73. package/dist/types/types.d.ts +21 -0
  74. package/dist/types/validate.d.ts +44 -0
  75. package/dist/types/value/Box3.d.ts +34 -0
  76. package/dist/types/value/Color.d.ts +71 -0
  77. package/dist/types/value/Euler.d.ts +35 -0
  78. package/dist/types/value/Mat4.d.ts +30 -0
  79. package/dist/types/value/Quat.d.ts +74 -0
  80. package/dist/types/value/Ray.d.ts +43 -0
  81. package/dist/types/value/Vec3.d.ts +88 -0
  82. package/dist/types/value/cssColors.d.ts +2 -0
  83. package/dist/types/watch.d.ts +14 -0
  84. package/dist/types/webgl/WebGLRenderer.d.ts +117 -0
  85. package/dist/types/webgl/context.d.ts +67 -0
  86. package/dist/types/webgl/passes.d.ts +66 -0
  87. package/dist/types/webgl/picking.d.ts +52 -0
  88. package/dist/types/webgl/programs.d.ts +68 -0
  89. package/dist/types/webgl/resources.d.ts +86 -0
  90. package/dist/types/webgl/shaders.d.ts +28 -0
  91. package/package.json +75 -4
  92. package/schema/chart.schema.json +186 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2013-2026 Kevin Roast
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,133 @@
1
- # Temporary Holding Version
1
+ # phoria2
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Small, friendly 3D for the web. A WebGL 2 renderer with PBR materials, instancing, points, lines,
4
+ labels, picking and particles, behind an API small enough to learn in an afternoon - aimed at
5
+ business apps: charts, labelled scenes, diagrams, dashboards and product viewers.
6
+
7
+ - **Small**: about 46 KB gzipped for a lit, interactive scene; charts, particles and glTF are
8
+ separate imports, and the heavier parts (shadows, HDR environments, GPU picking) load only when used.
9
+ - **Idle when nothing changes**: a view draws only when something in it changed, so a dashboard of
10
+ many views costs nothing at rest.
11
+ - **Tells you what to write**: every option is checked, and a mistake throws an error that names
12
+ the fix - pass `colour` and you get `Material: use 'color'`. Written to be easy for coding
13
+ agents too.
14
+ - **No runtime dependencies.** ES modules, with TypeScript types.
15
+
16
+ ## Install
17
+
18
+ ```sh
19
+ npm install phoria2
20
+ ```
21
+
22
+ Or straight from a CDN, with no build step:
23
+
24
+ ```html
25
+ <script type="module">
26
+ import { View, Mesh, box } from 'https://cdn.jsdelivr.net/npm/phoria2/+esm'
27
+ </script>
28
+ ```
29
+
30
+ ## A first scene
31
+
32
+ ```html
33
+ <canvas id="c" style="width: 100%; height: 100vh; display: block"></canvas>
34
+ <script type="module" src="./main.js"></script>
35
+ ```
36
+
37
+ ```js
38
+ import { View, Mesh, box, DirectionalLight } from 'phoria2'
39
+
40
+ const view = new View({ canvas: '#c', orbit: true, background: '#1c1c20' })
41
+ const cube = view.scene.add(new Mesh({ geometry: box(2), material: { color: 'orange' } }))
42
+ view.scene.add(new DirectionalLight({ direction: [-1, -2, -1] }))
43
+ view.start((dt) => cube.rotateY(0.6 * dt))
44
+ ```
45
+
46
+ The canvas takes its size from CSS; the view matches its drawing buffer to it and follows resizes.
47
+ The camera starts fitted to the scene, and `orbit: true` lets the user turn, pan and zoom it.
48
+
49
+ ## Charts
50
+
51
+ ```js
52
+ import { View } from 'phoria2'
53
+ import { chart } from 'phoria2/charts'
54
+
55
+ const view = new View({ canvas: '#c', orbit: true })
56
+ view.scene.add(chart({
57
+ mark: 'bar',
58
+ data: rows, // [{ month: 'Jan', region: 'North', sales: 41 }, ...]
59
+ x: 'month', z: 'region', y: 'sales',
60
+ color: 'region',
61
+ tooltip: true,
62
+ }))
63
+ ```
64
+
65
+ Marks: `bar`, `point`, `line`, `area`, `surface` and `network`, with axes, legends, labels, tooltips
66
+ and animated updates (`chart.update(newRows)`). A JSON schema for specs ships as
67
+ `phoria2/charts/schema.json`.
68
+
69
+ ## Models
70
+
71
+ ```js
72
+ import { loadGLTF } from 'phoria2/gltf'
73
+
74
+ const model = await loadGLTF('models/chair.glb') // .glb or .gltf
75
+ view.scene.add(model)
76
+ view.frame(model)
77
+ model.play() // its first animation
78
+ ```
79
+
80
+ ## With React
81
+
82
+ React owns the canvas; phoria2 draws on it. Make the view once, dispose of it on unmount, and
83
+ change the scene in place when props change:
84
+
85
+ ```jsx
86
+ import { useEffect, useRef } from 'react'
87
+ import { View, Mesh, box } from 'phoria2'
88
+
89
+ export function SpinningBox({ color }) {
90
+ const canvas = useRef(null)
91
+ const mesh = useRef(null)
92
+
93
+ useEffect(() => {
94
+ const view = new View({ canvas: canvas.current, orbit: true })
95
+ mesh.current = view.scene.add(new Mesh({ geometry: box(2) }))
96
+ view.start((dt) => mesh.current.rotateY(0.6 * dt))
97
+ return () => view.dispose()
98
+ }, [])
99
+
100
+ useEffect(() => {
101
+ mesh.current.material.color.set(color)
102
+ }, [color])
103
+
104
+ return <canvas ref={canvas} style={{ width: '100%', height: 320 }} />
105
+ }
106
+ ```
107
+
108
+ A full example, with a chart that follows its data, is in
109
+ [`examples/react`](https://github.com/kevinroast/kevs3d/tree/master/phoria2/examples/react).
110
+
111
+ ## What's in the package
112
+
113
+ | Import | |
114
+ |---|---|
115
+ | `phoria2` | the view, scene graph, cameras, lights, materials, geometry, textures, picking, labels, `create()` from JSON |
116
+ | `phoria2/charts` | `chart()` - charts from a spec of mark, data and channels, and the scales they use |
117
+ | `phoria2/particles` | `Emitter` and `Body` |
118
+ | `phoria2/gltf` | `loadGLTF()` - glTF 2.0 models with their materials and animations |
119
+
120
+ ## Browsers
121
+
122
+ Any browser with WebGL 2: current Chrome, Edge, Firefox and Safari (desktop and iOS 15+).
123
+
124
+ ## Examples
125
+
126
+ The demo gallery shows each feature and a few showcase scenes; its source is in
127
+ [`demos/`](https://github.com/kevinroast/kevs3d/tree/master/phoria2/demos). The design and the
128
+ reasoning behind the API are in [`API-DESIGN.md`](https://github.com/kevinroast/kevs3d/blob/master/phoria2/API-DESIGN.md).
129
+
130
+ ## Licence
131
+
132
+ MIT - see [LICENSE](LICENSE). phoria2 is a rewrite of phoria, a 2013 library that drew 3D on the
133
+ canvas 2D context.