customforge 0.1.0-alpha.0
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.
- package/CHANGELOG.md +27 -0
- package/LICENSE +201 -0
- package/README.md +299 -0
- package/README.zh-CN.md +299 -0
- package/dist/bridge/TextureBridge.d.ts +31 -0
- package/dist/bridge/TextureBridge.d.ts.map +1 -0
- package/dist/core/config.d.ts +26 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/design.d.ts +12 -0
- package/dist/core/design.d.ts.map +1 -0
- package/dist/core/dom.d.ts +11 -0
- package/dist/core/dom.d.ts.map +1 -0
- package/dist/core/types.d.ts +167 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/customizer/ProductCustomizer.d.ts +106 -0
- package/dist/customizer/ProductCustomizer.d.ts.map +1 -0
- package/dist/editor/DesignEditor.d.ts +130 -0
- package/dist/editor/DesignEditor.d.ts.map +1 -0
- package/dist/editor/imageSource.d.ts +11 -0
- package/dist/editor/imageSource.d.ts.map +1 -0
- package/dist/editor/objectBounds.d.ts +39 -0
- package/dist/editor/objectBounds.d.ts.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1139 -0
- package/dist/index.js.map +1 -0
- package/dist/style.css +12 -0
- package/dist/viewer/ProductViewer.d.ts +64 -0
- package/dist/viewer/ProductViewer.d.ts.map +1 -0
- package/package.json +74 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to CustomForge will be documented in this file
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
## [0.1.0-alpha.0] - 2026-08-27
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- ESM Library build configuration with source maps
|
|
12
|
+
- TypeScript declaration and declaration map generation
|
|
13
|
+
- Namespaced core stylesheet exported as `customforge/style.css`
|
|
14
|
+
- Local package verification and npm consumer example
|
|
15
|
+
- Versioned, Fabric-independent Design JSON types and runtime validation
|
|
16
|
+
- Public `saveDesign()` and transactional `loadDesign()` methods
|
|
17
|
+
- Design JSON save and load controls in the built-in and npm consumer demos
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- Fabric.js and Three.js are peer dependencies for Library consumers
|
|
22
|
+
- Demo-only Lucide icons are development dependencies
|
|
23
|
+
- `ProductCustomizer` no longer exposes its Fabric.js editor or Three.js viewer instances
|
|
24
|
+
- Package version `0.1.0-alpha.0` is configured for public releases under the `alpha` dist-tag
|
|
25
|
+
- Text and image objects remain fully inside the editor canvas while being added or transformed
|
|
26
|
+
- The built-in demo product no longer includes the obstructive torus handle
|
|
27
|
+
- Blob URL images are converted to persistent Data URLs when added
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# CustomForge
|
|
4
|
+
|
|
5
|
+
**Turn a 2D texture canvas into a live 3D product preview**
|
|
6
|
+
|
|
7
|
+
A lightweight, framework-agnostic prototype for building browser-based product customization experiences with Fabric.js and Three.js
|
|
8
|
+
|
|
9
|
+
<p>
|
|
10
|
+
<img alt="TypeScript" src="https://img.shields.io/badge/TypeScript-strict-3178C6?logo=typescript&logoColor=white">
|
|
11
|
+
<img alt="Vite" src="https://img.shields.io/badge/Vite-8-646CFF?logo=vite&logoColor=white">
|
|
12
|
+
<img alt="Three.js" src="https://img.shields.io/badge/Three.js-r185-111111?logo=threedotjs&logoColor=white">
|
|
13
|
+
<img alt="Fabric.js" src="https://img.shields.io/badge/Fabric.js-7-DB4D6D">
|
|
14
|
+
<img alt="License" src="https://img.shields.io/badge/License-Apache%202.0-2F6F9F">
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<p>
|
|
18
|
+
<strong>English</strong> |
|
|
19
|
+
<a href="./README.zh-CN.md">中文简体</a>
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## What It Does
|
|
27
|
+
|
|
28
|
+
CustomForge connects a familiar 2D design surface to a UV-mapped 3D model:
|
|
29
|
+
|
|
30
|
+
- Add and edit text on a 2D texture canvas
|
|
31
|
+
- Upload, move, scale, and rotate images
|
|
32
|
+
- Preview every canvas change on a 3D product in real time
|
|
33
|
+
- Load remote GLB/GLTF models and optional base textures
|
|
34
|
+
- Select the customizable surface by mesh name
|
|
35
|
+
- Rotate and zoom the 3D preview with OrbitControls
|
|
36
|
+
- Export the composed texture as a PNG
|
|
37
|
+
- Save and restore editable objects through versioned Design JSON
|
|
38
|
+
|
|
39
|
+
The included workbench starts with a procedural cup, so the project works immediately without external assets
|
|
40
|
+
|
|
41
|
+
## Repository Development
|
|
42
|
+
|
|
43
|
+
Requirements: Node.js 22+ and pnpm 11+
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pnpm install
|
|
47
|
+
pnpm dev
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Open the URL printed by Vite
|
|
51
|
+
|
|
52
|
+
The built-in demo appears with a UV workspace on the left and a live 3D preview on the right
|
|
53
|
+
|
|
54
|
+
## npm Alpha Package
|
|
55
|
+
|
|
56
|
+
CustomForge is prepared for public alpha releases under the `alpha` dist-tag. The API and Design JSON Schema may change between alpha versions
|
|
57
|
+
|
|
58
|
+
After the first release is published, install the current alpha and its peer dependencies with:
|
|
59
|
+
|
|
60
|
+
```powershell
|
|
61
|
+
pnpm add customforge@alpha
|
|
62
|
+
pnpm add fabric three
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
For repository-independent verification before publishing, build and create the local package from the repository root:
|
|
66
|
+
|
|
67
|
+
```powershell
|
|
68
|
+
pnpm pack:local
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The command builds JavaScript, TypeScript declarations, and core styles, checks the npm file list, and creates:
|
|
72
|
+
|
|
73
|
+
```text
|
|
74
|
+
customforge-0.1.0-alpha.0.tgz
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Install that local package and its peer dependencies in an independent Vite TypeScript project:
|
|
78
|
+
|
|
79
|
+
```powershell
|
|
80
|
+
pnpm add D:\project\CustomForge\CustomForge\customforge-0.1.0-alpha.0.tgz
|
|
81
|
+
pnpm add fabric three
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The checked-in `examples/npm-consumer` project imports CustomForge only through this `.tgz`. Run `pnpm install --ignore-workspace` in that directory so pnpm installs it independently from the parent workspace
|
|
85
|
+
|
|
86
|
+
## Load Your Product
|
|
87
|
+
|
|
88
|
+
Choose **Load remote** in the demo and provide:
|
|
89
|
+
|
|
90
|
+
| Field | Purpose |
|
|
91
|
+
| --- | --- |
|
|
92
|
+
| GLB / GLTF URL | URL of the UV-mapped 3D product model |
|
|
93
|
+
| Base texture URL | Optional image shown underneath editable objects |
|
|
94
|
+
| Customizable mesh | Name of the mesh that receives the live canvas texture |
|
|
95
|
+
| Flip texture vertically | Corrects texture orientation when required by the model |
|
|
96
|
+
|
|
97
|
+
UV coordinates are expected to be stored in the 3D model
|
|
98
|
+
|
|
99
|
+
The optional texture image is the visual base layer, not a replacement for model UV data
|
|
100
|
+
|
|
101
|
+
> [!IMPORTANT]
|
|
102
|
+
> Remote models, textures, decals, and fonts must be served with CORS headers that allow the app origin
|
|
103
|
+
>
|
|
104
|
+
> A blocked or canvas-tainting resource may fail to load and can prevent PNG export
|
|
105
|
+
|
|
106
|
+
## Basic Usage
|
|
107
|
+
|
|
108
|
+
The framework-independent Library entry can be mounted into any two DOM containers:
|
|
109
|
+
|
|
110
|
+
CustomForge is browser-only and must be initialized after its DOM containers are available
|
|
111
|
+
|
|
112
|
+
The editor and viewer require two different containers; call `destroy()` when the page, host component, or instance is no longer in use to release Fabric, WebGL, observer, and event resources
|
|
113
|
+
|
|
114
|
+
```html
|
|
115
|
+
<div id="texture-editor"></div>
|
|
116
|
+
<div id="product-viewer"></div>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { createCustomizer } from 'customforge'
|
|
121
|
+
import 'customforge/style.css'
|
|
122
|
+
|
|
123
|
+
const customizer = await createCustomizer({
|
|
124
|
+
editor: '#texture-editor',
|
|
125
|
+
viewer: '#product-viewer',
|
|
126
|
+
editorWidth: 1024,
|
|
127
|
+
editorHeight: 512,
|
|
128
|
+
product: {
|
|
129
|
+
modelUrl: 'https://example.com/product.glb',
|
|
130
|
+
textureUrl: 'https://example.com/base-texture.png',
|
|
131
|
+
surfaceMesh: 'PrintArea',
|
|
132
|
+
textureFlipY: false,
|
|
133
|
+
},
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
customizer.addText({
|
|
137
|
+
text: 'Hello world',
|
|
138
|
+
x: 120,
|
|
139
|
+
y: 180,
|
|
140
|
+
fontSize: 64,
|
|
141
|
+
color: '#172126',
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
await customizer.addImage({
|
|
145
|
+
src: 'https://example.com/logo.png',
|
|
146
|
+
x: 720,
|
|
147
|
+
y: 240,
|
|
148
|
+
width: 220,
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
window.addEventListener('beforeunload', () => customizer.destroy(), {
|
|
152
|
+
once: true,
|
|
153
|
+
})
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
The public package uses the same root and style imports as the local `.tgz`; pin an exact alpha version when reproducible installs are required
|
|
157
|
+
|
|
158
|
+
## Design JSON
|
|
159
|
+
|
|
160
|
+
`saveDesign()` returns a Library-owned, JSON-safe document instead of exposing Fabric.js serialization. `loadDesign()` validates unknown input and restores the editable object stack asynchronously:
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
const design = customizer.saveDesign()
|
|
164
|
+
localStorage.setItem('customforge-design', JSON.stringify(design))
|
|
165
|
+
|
|
166
|
+
const savedDesign = localStorage.getItem('customforge-design')
|
|
167
|
+
if (savedDesign) {
|
|
168
|
+
await customizer.loadDesign(JSON.parse(savedDesign))
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
The current Schema version is `1`. It stores the logical canvas size and the text and image objects in back-to-front render order, including stable object IDs and center-based transforms
|
|
173
|
+
|
|
174
|
+
Design JSON intentionally excludes the product model, target mesh, and base texture. A document can only be loaded into an editor with exactly the same logical width and height
|
|
175
|
+
|
|
176
|
+
Loading is transactional: the current design remains unchanged unless the document validates and every referenced image loads successfully. Blob URL images are converted to Data URLs when added; remote image URLs remain URLs and must continue to satisfy browser CORS requirements when restored
|
|
177
|
+
|
|
178
|
+
The Schema is still an alpha contract and may change in later alpha versions
|
|
179
|
+
|
|
180
|
+
## Instance API
|
|
181
|
+
|
|
182
|
+
| Method | Description |
|
|
183
|
+
| --- | --- |
|
|
184
|
+
| `addText(options)` | Add and select editable text, constrained to the canvas |
|
|
185
|
+
| `addImage(options)` | Load and select an image, constrained to the canvas |
|
|
186
|
+
| `deleteSelected()` | Remove the active object or selection |
|
|
187
|
+
| `saveDesign()` | Return the current versioned Design JSON document |
|
|
188
|
+
| `loadDesign(value)` | Validate and transactionally restore Design JSON |
|
|
189
|
+
| `loadProduct(product)` | Replace the model, base texture, and target mesh |
|
|
190
|
+
| `exportTexture(filename?)` | Download the composed texture as PNG |
|
|
191
|
+
| `resetView()` | Restore the default 3D camera position |
|
|
192
|
+
| `on(event, listener)` | Subscribe to instance events; returns an unsubscribe function |
|
|
193
|
+
| `destroy()` | Release DOM events, Fabric state, and WebGL resources |
|
|
194
|
+
|
|
195
|
+
Available events are `ready`, `change`, `selectionchange`, `status`, and `error`
|
|
196
|
+
|
|
197
|
+
The initial alpha stability boundary is limited to the methods above, `createCustomizer`, `ProductCustomizer`, and the configuration, event, and Design JSON types exported from the package root
|
|
198
|
+
|
|
199
|
+
`ProductCustomizer` does not expose its Fabric.js editor or Three.js viewer instances; consumers interact through the facade API
|
|
200
|
+
|
|
201
|
+
Imports from `core`, `editor`, `viewer`, `bridge`, or any other undeclared package subpath are unsupported
|
|
202
|
+
|
|
203
|
+
## Architecture
|
|
204
|
+
|
|
205
|
+
```mermaid
|
|
206
|
+
flowchart LR
|
|
207
|
+
A[Text and images] --> B[DesignEditor]
|
|
208
|
+
C[Base texture] --> B
|
|
209
|
+
B --> D[HTML Canvas]
|
|
210
|
+
D --> E[TextureBridge]
|
|
211
|
+
E --> F[Three.js CanvasTexture]
|
|
212
|
+
G[GLB / GLTF model] --> H[ProductViewer]
|
|
213
|
+
F --> H
|
|
214
|
+
H --> I[Customizable mesh]
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
```text
|
|
218
|
+
ProductCustomizer
|
|
219
|
+
|-- DesignEditor Fabric.js rendering and object interaction
|
|
220
|
+
|-- ProductViewer Three.js scene, model, material, and camera
|
|
221
|
+
`-- TextureBridge Canvas-to-material synchronization
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
`ProductCustomizer` coordinates the modules while keeping Fabric.js and Three.js details behind a small instance API
|
|
225
|
+
|
|
226
|
+
The demo UI uses Vanilla TypeScript; the core does not depend on Vue, React, or another UI framework
|
|
227
|
+
|
|
228
|
+
## Model Contract
|
|
229
|
+
|
|
230
|
+
The current prototype expects:
|
|
231
|
+
|
|
232
|
+
- A GLB or GLTF model with valid UV coordinates
|
|
233
|
+
- An uncompressed model that can be loaded by the standard Three.js `GLTFLoader`
|
|
234
|
+
- A named mesh for the customizable surface, such as `PrintArea`
|
|
235
|
+
- The target texture in the first material slot of that mesh
|
|
236
|
+
- Remote asset URLs accessible under the browser's CORS policy
|
|
237
|
+
|
|
238
|
+
The built-in demo follows the same `PrintArea` mesh convention
|
|
239
|
+
|
|
240
|
+
## Project Structure
|
|
241
|
+
|
|
242
|
+
```text
|
|
243
|
+
src/
|
|
244
|
+
|-- bridge/ Canvas and Three.js texture synchronization
|
|
245
|
+
|-- core/ Public types, configuration, and DOM helpers
|
|
246
|
+
|-- customizer/ Public instance orchestration
|
|
247
|
+
|-- demo/ Runnable workbench UI
|
|
248
|
+
|-- editor/ Fabric.js design surface
|
|
249
|
+
|-- style.css Public Library style entry
|
|
250
|
+
|-- styles/ Library core styles
|
|
251
|
+
|-- viewer/ Three.js product preview
|
|
252
|
+
`-- index.ts Framework-independent source entry
|
|
253
|
+
|
|
254
|
+
examples/
|
|
255
|
+
`-- npm-consumer/ Independent local .tgz consumer
|
|
256
|
+
|
|
257
|
+
scripts/
|
|
258
|
+
`-- verify-package.mjs npm file and artifact boundary checks
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Development Commands
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
pnpm check # TypeScript project check
|
|
265
|
+
pnpm test # Unit tests
|
|
266
|
+
pnpm build # Type-check and production build
|
|
267
|
+
pnpm build:lib # Build ESM, declarations, and core styles
|
|
268
|
+
pnpm verify:package # Check dist and the npm file list
|
|
269
|
+
pnpm pack:local # Build, verify, and create the local .tgz
|
|
270
|
+
pnpm release:check # Run checks, tests, package build, verification, and local pack
|
|
271
|
+
pnpm preview # Preview the production build
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Current Scope
|
|
275
|
+
|
|
276
|
+
This is an early technical prototype
|
|
277
|
+
|
|
278
|
+
The public API and design document format are not stable yet
|
|
279
|
+
|
|
280
|
+
The current milestone intentionally focuses on one texture and one customizable mesh
|
|
281
|
+
|
|
282
|
+
Public npm releases use the `alpha` dist-tag until the API and Design JSON contract are ready for a more stable channel
|
|
283
|
+
|
|
284
|
+
Multi-surface products, undo/redo, and framework adapters are not implemented yet. Undo/redo is the next planned milestone and will build on the Design JSON snapshot contract
|
|
285
|
+
|
|
286
|
+
## Technology
|
|
287
|
+
|
|
288
|
+
- [Fabric.js](https://fabricjs.com/) for the 2D editing surface
|
|
289
|
+
- [Three.js](https://threejs.org/) for model loading and real-time 3D rendering
|
|
290
|
+
- [Vite](https://vite.dev/) for development and application builds
|
|
291
|
+
- [TypeScript](https://www.typescriptlang.org/) with strict checking enabled
|
|
292
|
+
|
|
293
|
+
## License
|
|
294
|
+
|
|
295
|
+
CustomForge is licensed under the Apache License 2.0
|
|
296
|
+
|
|
297
|
+
See [LICENSE](./LICENSE) for the full license terms
|
|
298
|
+
|
|
299
|
+
Third-party dependencies and assets remain subject to their respective licenses
|