@vincentt-xr/sdk 2.0.0-alpha.12 → 2.0.0-alpha.14
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/GROUNDING.md +70 -16
- package/dist/{TextLabel-C6F5xoaz.js → TextLabel--skGFws8.js} +1 -1
- package/dist/{TextLabel-ChZCoB3P.cjs → TextLabel-DPJBtkUS.cjs} +1 -1
- package/dist/components/ScreenImage/ScreenImage.d.ts +1 -1
- package/dist/components/ScreenImage/liveEditable.d.ts +12 -0
- package/dist/components/ScreenImage/types.d.ts +20 -2
- package/dist/components/ScreenText/index.d.ts +1 -1
- package/dist/components/ScreenText/liveEditable.d.ts +6 -0
- package/dist/components/TextLabel/types.d.ts +4 -1
- package/dist/debug-ui.cjs +1 -1
- package/dist/debug-ui.js +2 -2
- package/dist/{index-BzGLgXJm.cjs → index-BG4xgyTm.cjs} +5 -5
- package/dist/index-CD_JFx3g.js +1142 -0
- package/dist/{index-BaNlidsb.js → index-YI3Yidg_.js} +1 -1
- package/dist/{index-Cm3v6Dlg.cjs → index-nRQNXOVk.cjs} +1 -1
- package/dist/instructions.cjs +1 -1
- package/dist/instructions.js +1 -1
- package/dist/main.cjs +1 -1
- package/dist/main.js +4 -4
- package/dist/scene-object.cjs +1 -1
- package/dist/scene-object.js +1 -1
- package/dist/useEditOverrides-C8Kzr6M7.cjs +1 -0
- package/dist/useEditOverrides-DpPTA6BW.js +40 -0
- package/dist/utils/useEditOverrides.d.ts +1 -1
- package/package.json +1 -1
- package/settings.json +98 -4
- package/dist/index-bL819L-K.js +0 -1115
- package/dist/useEditOverrides-BTkPGVjN.js +0 -38
- package/dist/useEditOverrides-C3ZVXuIH.cjs +0 -1
package/GROUNDING.md
CHANGED
|
@@ -123,12 +123,20 @@ nothing to an app bundle.
|
|
|
123
123
|
|
|
124
124
|
- Components are keyed by export name; props by dotted path into object props
|
|
125
125
|
(`screenTransform.position`, `settings.fillColor`).
|
|
126
|
-
- `type` is one of `number`, `color`, `boolean`, `vec2`, `vec3`, `euler`, `enum
|
|
127
|
-
A `vec2`/`vec3` is either a number tuple (`[x, y]`) or an
|
|
128
|
-
number fields (`{ x, y }`, `{ width, height }`); the
|
|
129
|
-
written in source. An `enum` lists its values in
|
|
126
|
+
- `type` is one of `number`, `color`, `boolean`, `vec2`, `vec3`, `euler`, `enum`,
|
|
127
|
+
`text`, `asset`. A `vec2`/`vec3` is either a number tuple (`[x, y]`) or an
|
|
128
|
+
object of two or three number fields (`{ x, y }`, `{ width, height }`); the
|
|
129
|
+
editor follows the literal written in source. An `enum` lists its values in
|
|
130
|
+
`enum`.
|
|
130
131
|
- `min`, `max`, `step` and `unit` (`px`, `m`, `deg`, `rad`, `ratio`) apply to
|
|
131
132
|
`number`, `vec2`, `vec3` and `euler`; `label` to any type.
|
|
133
|
+
- A `text` setting is words shown on screen: `maxLength` is the most code points
|
|
134
|
+
the editor accepts (at most 500), and `multiline: true` allows line breaks.
|
|
135
|
+
- An `asset` setting is a file reference; `accept` lists the kinds of file it
|
|
136
|
+
takes (only `"image"` today).
|
|
137
|
+
- `overriddenBy` lists other props of the component that, when written, make the
|
|
138
|
+
setting ignored at run time. The editor hides the setting on an element that
|
|
139
|
+
has one of them (`ScreenImage.src` is `overriddenBy: ["source"]`).
|
|
132
140
|
- `element` puts a component on the editor's **supported list** as one list kind
|
|
133
141
|
(`screenText`, `screenImage`, `screenShape`), and `supported: true` marks the
|
|
134
142
|
settings the editor shows for it. The editor shows only supported settings on
|
|
@@ -160,6 +168,23 @@ double-quoted. A tag on a shared props type (`TextLabelProps`,
|
|
|
160
168
|
`ScreenTransform2DSettings`) declares the setting for every exported component
|
|
161
169
|
that reaches it.
|
|
162
170
|
|
|
171
|
+
`text` and `asset` are always named, on a string prop. `maxLength=` (a whole
|
|
172
|
+
number from 1 to 500) and `multiline=true|false` apply to `text`; `accept=`
|
|
173
|
+
(comma-separated, `image`) is required on `asset`; `overriddenBy=` takes
|
|
174
|
+
comma-separated top-level prop names of the component and applies to any type.
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
export type ScreenImageProps = {
|
|
178
|
+
source?: ScreenImageSource;
|
|
179
|
+
/** @tweak asset accept=image overriddenBy=source */
|
|
180
|
+
src?: string;
|
|
181
|
+
};
|
|
182
|
+
export type TextLabelProps = {
|
|
183
|
+
/** @tweak text maxLength=500 multiline=true */
|
|
184
|
+
text: string;
|
|
185
|
+
};
|
|
186
|
+
```
|
|
187
|
+
|
|
163
188
|
**SDK authors: put a component on the supported list with `@editorElement`** on
|
|
164
189
|
the component's own declaration: the list kind, then the dotted paths of the
|
|
165
190
|
settings the editor should show. Each path must be a `@tweak` setting that
|
|
@@ -174,16 +199,28 @@ export const ScreenShape = (props: ScreenShapeProps) => {
|
|
|
174
199
|
};
|
|
175
200
|
```
|
|
176
201
|
|
|
177
|
-
Listed today: `ScreenText` (`
|
|
178
|
-
`.size`, `.rotation`), `ScreenImage` (`
|
|
179
|
-
|
|
180
|
-
`
|
|
202
|
+
Listed today: `ScreenText` (`text`, `fontSize`, `color`,
|
|
203
|
+
`screenTransform.position`, `.size`, `.rotation`), `ScreenImage` (`src`,
|
|
204
|
+
`opacity`, `fit`, `transform.position`, `.size`, `.rotation`, `anchors.left`,
|
|
205
|
+
`.right`, `.top`, `.bottom`) and `ScreenShape` (`transform.position`, `.size`,
|
|
206
|
+
`.rotation`, `settings.fillColor`).
|
|
207
|
+
|
|
208
|
+
The editor offers an element only when at least one of its listed settings is
|
|
209
|
+
written as a plain value. A `ScreenImage` placed with `anchors` and no
|
|
210
|
+
`transform` (a full-screen frame:
|
|
211
|
+
`anchors={{ left: -1, right: 1, top: 1, bottom: -1 }}`) moves and resizes in the
|
|
212
|
+
editor when all four edges are written as number literals in that object: a
|
|
213
|
+
move shifts every edge by the same amount, a resize moves only the dragged
|
|
214
|
+
edges, and it never rotates. With an edge missing, the editor shows the written
|
|
215
|
+
edges as values but draws no handles.
|
|
181
216
|
|
|
182
217
|
`pnpm settings:generate` rewrites `settings.json`; commit the result. CI runs
|
|
183
218
|
`pnpm settings:check` and fails when the file does not match the tags or the
|
|
184
219
|
`package.json` version, so a version bump regenerates it too. The generator
|
|
185
220
|
also fails on a malformed tag, an unknown key or unit, a type that does not fit
|
|
186
|
-
the prop,
|
|
221
|
+
the prop, a `text`/`asset` key on another type, an `asset` without `accept`, an
|
|
222
|
+
`overriddenBy` that does not name another prop of the component, and a
|
|
223
|
+
`@tweak` that no exported component reaches. It also fails on
|
|
187
224
|
an `@editorElement` with an unknown kind, no settings, a path that is not a
|
|
188
225
|
`@tweak` setting of that component, a second tag on one component, or a tag
|
|
189
226
|
that is not on an exported component.
|
|
@@ -191,8 +228,9 @@ that is not on an exported component.
|
|
|
191
228
|
### Live preview of unsaved editor changes
|
|
192
229
|
|
|
193
230
|
In the console's visual editor, an unsaved change to one of these settings
|
|
194
|
-
shows in the running app at once: `<ScreenText>` colour, font size and
|
|
195
|
-
placement; `<ScreenImage>`
|
|
231
|
+
shows in the running app at once: `<ScreenText>` text, colour, font size and
|
|
232
|
+
screen placement; `<ScreenImage>` image (`src`, only when no `source` prop is
|
|
233
|
+
written), opacity, fit and screen placement; `<ScreenShape>` screen placement
|
|
196
234
|
and fill colour; `<TextLabel>` colour. Other changes show after Save, which
|
|
197
235
|
rebuilds the app. The editor's build defines a small override store on the
|
|
198
236
|
page, and those components read it for those settings. Published and
|
|
@@ -200,9 +238,9 @@ preview builds have no store, so they render the props exactly as written.
|
|
|
200
238
|
App code does nothing for this and must not define or read
|
|
201
239
|
`__VCT_EDIT_OVERRIDES__`.
|
|
202
240
|
|
|
203
|
-
SDK authors: to make another prop live, add its key to the component's
|
|
204
|
-
`
|
|
205
|
-
`TextLabel`). A key is the prop name or a dotted path into an object prop
|
|
241
|
+
SDK authors: to make another prop live, add its key to the component's live
|
|
242
|
+
list (`liveEditable.ts` beside `ScreenText` and `ScreenImage`, `LIVE_EDITABLE`
|
|
243
|
+
in `ScreenShape` and `TextLabel`). A key is the prop name or a dotted path into an object prop
|
|
206
244
|
(`settings.fillColor`, `transform.position`), the same key as in
|
|
207
245
|
`settings.json`. A dotted key replaces only that leaf, copying the objects
|
|
208
246
|
around it, and is skipped when the parent object is not written. The hook is
|
|
@@ -292,6 +330,15 @@ authoring prefer `position`, `size`, and `rotation`. `anchors` still exist as
|
|
|
292
330
|
the lower-level layout escape hatch. If no source is provided, it renders the
|
|
293
331
|
SDK-owned square default image.
|
|
294
332
|
|
|
333
|
+
**Placeholder images: always use `src`.** An image that is a placeholder or is
|
|
334
|
+
"to be replaced" is written as
|
|
335
|
+
`<ScreenImage src="/images/placeholder.png" ... />` (the template ships that
|
|
336
|
+
file), never `source={{ kind: "default" }}` and never `source={{ kind: "image",
|
|
337
|
+
src }}`. Only a `src` image can be swapped in the visual editor: `source` wins
|
|
338
|
+
over `src` whenever both are set, so the editor does not offer an image swap on a
|
|
339
|
+
`ScreenImage` that has a `source` prop. Keep `source` for GIFs, textures and
|
|
340
|
+
media a program produces.
|
|
341
|
+
|
|
295
342
|
### `<ScreenShape>` — editable vector primitives
|
|
296
343
|
|
|
297
344
|
Use `ScreenShape` for circles, ellipses, rectangles, rounded rectangles, regular
|
|
@@ -389,7 +436,7 @@ import { ScreenImage, ScreenSpaceUI } from "@vincentt-xr/sdk";
|
|
|
389
436
|
<ScreenSpaceUI>
|
|
390
437
|
<ScreenImage
|
|
391
438
|
name="logo"
|
|
392
|
-
|
|
439
|
+
src="https://cdn.../logo.png"
|
|
393
440
|
coordinateSpace="canvas"
|
|
394
441
|
canvasSize={{ width: 720, height: 1280 }}
|
|
395
442
|
position={[-180, 464]}
|
|
@@ -403,7 +450,8 @@ import { ScreenImage, ScreenSpaceUI } from "@vincentt-xr/sdk";
|
|
|
403
450
|
Props:
|
|
404
451
|
|
|
405
452
|
- `source`: `{ kind: "default" }`, `{ kind: "image", src }`, `{ kind: "gif", src }`, or `{ kind: "texture", texture }`.
|
|
406
|
-
- `src`: shorthand for `{ kind: "image", src }
|
|
453
|
+
- `src`: shorthand for `{ kind: "image", src }`, ignored while `source` is set.
|
|
454
|
+
The form to use for a still image, because the visual editor can swap it.
|
|
407
455
|
- `fit`: `"stretch" | "contain" | "cover"`; default `"contain"`.
|
|
408
456
|
- `coordinateSpace`: `"normalized" | "canvas"`; default `"normalized"`.
|
|
409
457
|
- `canvasSize`: design canvas size for `coordinateSpace="canvas"`; default
|
|
@@ -7665,6 +7713,12 @@ import { ScreenSpaceUI, ScreenText } from "@vincentt-xr/sdk";
|
|
|
7665
7713
|
rectangle. The text renderer then aligns, shrinks, clips, or backgrounds the
|
|
7666
7714
|
text inside that rectangle.
|
|
7667
7715
|
|
|
7716
|
+
**Visual editor:** write `text` as a literal string (`text="Tap to start"` or
|
|
7717
|
+
`text={"Tap to start"}`), with no `lines` prop, when it should be editable in the
|
|
7718
|
+
visual editor (`lines` wins over `text` when both are set). Text
|
|
7719
|
+
built from an expression, a variable, a translation lookup or a template literal
|
|
7720
|
+
with `${...}` shows there as made by code and can only be changed in source.
|
|
7721
|
+
|
|
7668
7722
|
Use `ScreenText` when:
|
|
7669
7723
|
|
|
7670
7724
|
- you want top / center / bottom screen placement
|
|
@@ -2,7 +2,7 @@ import { jsx as z, jsxs as Te } from "react/jsx-runtime";
|
|
|
2
2
|
import { useMemo as B, forwardRef as xe, useEffect as be, useState as he, useRef as J } from "react";
|
|
3
3
|
import { useThree as Ce } from "@react-three/fiber";
|
|
4
4
|
import { b as Fe } from "./context-DTxSQvp4.js";
|
|
5
|
-
import { u as Le } from "./useEditOverrides-
|
|
5
|
+
import { u as Le } from "./useEditOverrides-DpPTA6BW.js";
|
|
6
6
|
import * as We from "three";
|
|
7
7
|
const et = ({ children: t, depth: e = 0 }) => {
|
|
8
8
|
const { camera: n, size: i } = Ce(), a = B(() => {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const H=require("react/jsx-runtime"),x=require("react"),ve=require("@react-three/fiber"),Me=require("./context-hA0Rb2Xa.cjs"),Te=require("./useEditOverrides-
|
|
1
|
+
"use strict";const H=require("react/jsx-runtime"),x=require("react"),ve=require("@react-three/fiber"),Me=require("./context-hA0Rb2Xa.cjs"),Te=require("./useEditOverrides-C8Kzr6M7.cjs"),xe=require("three");function Oe(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const Ce=Oe(xe),Le=({children:t,depth:e=0})=>{const{camera:n,size:r}=ve.useThree(),a=x.useMemo(()=>{if(!n.isPerspectiveCamera)return{width:10,height:10};const i=n,l=Math.abs(i.position.z-e),f=i.fov*Math.PI/180,s=2*Math.tan(f/2)*l;return{width:s*(r.width/r.height),height:s}},[n,r,e]);return H.jsx(Me.ScreenSpaceContext.Provider,{value:a,children:H.jsx("group",{position:[0,0,e],children:t})})},de=x.forwardRef(({texture:t,name:e,overlay:n,opacity:r,position:a,rotation:i,scale:l,visible:f,renderOrder:s},h)=>H.jsxs("mesh",{ref:h,name:e,position:a,rotation:i,scale:l,visible:f,renderOrder:s,children:[H.jsx("planeGeometry",{args:[1,1]}),H.jsx("meshBasicMaterial",{map:t,transparent:!0,opacity:r,depthTest:!n,depthWrite:!n})]}));de.displayName="TextLabelMesh";const Fe={color:"#ffffff",strokeWidth:0,strokeOpacity:1,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,shadowOpacity:1,fontWeight:"bold",fontStyle:"normal",fontFamily:"Arial, sans-serif",fontSize:48,textAlign:"center",verticalAlign:"center",minFontSize:12,letterSpacing:0,lineSpacing:.3,bgColor:"rgba(20,40,110,0.88)",bgFillMode:"solid",bgOpacity:1,bgFit:"full",bgTextureFit:"cover",bgTextureFlipX:!1,bgTextureFlipY:!1,borderWidth:0,borderRadius:24,padding:32,aspect:2.5,resolution:512,opacity:1,underline:!1,strikethrough:!1,bendPreset:"arc",bendStrength:0},ue=t=>{x.useEffect(()=>()=>{t==null||t.dispose()},[t])};function We(t,e,n){return n==="left"?e:n==="right"?t-e:t/2}function Ye(t,e,n,r,a){return a==="top"?e+n/2:a==="bottom"?t-e-r+n/2:t/2-(r-n)/2}function ke(t,e,n,r){return r==="full"||n==="left"?0:n==="right"?t-e:(t-e)/2}function be(t,e,n,r){return`${t} ${e} ${n}px ${r}`}function R(t,e){const n=Math.max(0,Math.min(e,1));return t*n*.08}function me(t,e){const n=Math.max(0,Math.min(e,1));return t*(1.2+n*.6)}function Se(t,e){"letterSpacing"in t&&(t.letterSpacing=`${e}px`)}function ye(t){"letterSpacing"in t&&(t.letterSpacing="0px")}function p(t,e,n){Se(t,n);const r=t.measureText(e).width;return ye(t),r}function J(t,e,n,r){return Math.max(1,Math.floor((t-e*2)/me(n,r)))}function Pe(t,e,n,r,a){return e.length<=r&&e.every(i=>p(t,i,a)<=n)}function V(t,e,n,r,a,i,l,f){t.font=be(r,a,i,l);const s=e.split(" "),h=[];let o="";for(const d of s){const c=o?`${o} ${d}`:d;p(t,c,f)>n&&o?(h.push(o),o=d):o=c}return o&&h.push(o),h}function fe(t,e,n,r,a,i,l,f){const h=e.split(/\r?\n/).flatMap(o=>o.trim().length===0?[""]:V(t,o,n,r,a,i,l,f));return h.length>0?h:[e]}function we(t,e,n,r,a){const i=r?"...":"";let l=e.trimEnd();for(;l.length>0&&p(t,`${l}${i}`,a)>n;)l=l.slice(0,-1).trimEnd();return`${l}${i}`}function K(t,e,n,r,a){return e.map((i,l)=>{if(p(t,i,a)<=n)return i;const f=l===e.length-1;return we(t,i,n,r==="ellipsis"&&f,a)})}function he(t,e,n,r,a,i){if(e.length<=n)return K(t,e,r,a?"ellipsis":"clip",i);const l=e.slice(0,n),f=l[n-1];return l[n-1]=we(t,f,r,a,i),K(t,l,r,a?"ellipsis":"clip",i)}function He(t){const{ctx:e,text:n,explicitLines:r,maxWidth:a,maxHeight:i,padding:l,fontStyle:f,fontWeight:s,fontSize:h,fontFamily:o,letterSpacing:d,lineSpacing:c,overflow:u,resizeToFit:S,minFontSize:g}=t;let b=h,m=R(b,d),y=r??fe(e,n,a,f,s,b,o,m),v=J(i,l,b,c);const C=S===!0||u==="shrink";for(;C&&!Pe(e,y,a,v,m)&&b>g&&(b=Math.max(g,b-4),m=R(b,d),y=r??fe(e,n,a,f,s,b,o,m),v=J(i,l,b,c),b!==g););return u==="ellipsis"?y=he(e,y,v,a,!0,m):u==="clamp"||u==="shrink"?y=he(e,y,v,a,!1,m):u!=="clip"&&(y=K(e,y,a,void 0,m)),{fontSize:b,lines:y}}function Xe(t){const{ctx:e,text:n,maxWidth:r,maxHeight:a,padding:i,fontStyle:l,fontWeight:f,fontSize:s,fontFamily:h,letterSpacing:o,lineSpacing:d}=t;let c=s,u=V(e,n,r,l,f,c,h,R(c,o));const S=J(a,i,c,d);return u.length>S&&(c=Math.max(12,Math.round(c*.75)),u=V(e,n,r,l,f,c,h,R(c,o))),{fontSize:c,lines:u}}function Q(t,e){return typeof OffscreenCanvas<"u"?new OffscreenCanvas(t,e):(()=>{const n=document.createElement("canvas");return n.width=t,n.height=e,n})()}function pe(t,e){const n=e.width-e.padding*2,a=Array.isArray(e.lines)||e.text.includes(`
|
|
2
2
|
`)||e.overflow!==void 0||e.resizeToFit!==void 0?He({ctx:t,text:e.text,explicitLines:e.lines,maxWidth:n,maxHeight:e.height,padding:e.padding,fontStyle:e.fontStyle,fontWeight:e.fontWeight,fontSize:e.fontSize,fontFamily:e.fontFamily,overflow:e.overflow,resizeToFit:e.resizeToFit,minFontSize:e.minFontSize,letterSpacing:e.letterSpacing,lineSpacing:e.lineSpacing}):Xe({ctx:t,text:e.text,maxWidth:n,maxHeight:e.height,padding:e.padding,fontStyle:e.fontStyle,fontWeight:e.fontWeight,fontSize:e.fontSize,fontFamily:e.fontFamily,letterSpacing:e.letterSpacing,lineSpacing:e.lineSpacing}),i=a.fontSize,l=a.lines;t.font=be(e.fontStyle,e.fontWeight,i,e.fontFamily);const f=R(i,e.letterSpacing),s=me(i,e.lineSpacing),h=Math.max(i,i+(l.length-1)*s),o=Ye(e.height,e.padding,i,h,e.verticalAlign),d=l.map(c=>p(t,c,f));return{fontSize:i,resolvedLines:l,letterSpacingPx:f,lineHeight:s,startY:o,textBlockWidth:Math.min(e.width,Math.max(0,Math.max(...d,0))+e.padding*2),textBlockHeight:Math.min(e.height,h+e.padding*2),textX:We(e.width,e.padding,e.textAlign)}}function Ae(t,e,n,r,a,i){t.beginPath(),t.moveTo(e+i,n),t.lineTo(e+r-i,n),t.quadraticCurveTo(e+r,n,e+r,n+i),t.lineTo(e+r,n+a-i),t.quadraticCurveTo(e+r,n+a,e+r-i,n+a),t.lineTo(e+i,n+a),t.quadraticCurveTo(e,n+a,e,n+a-i),t.lineTo(e,n+i),t.quadraticCurveTo(e,n,e+i,n),t.closePath()}function ce(t,e,n){return typeof t!="number"||Number.isNaN(t)||t<=0?e:Math.min(t,n)}function Be(t,e){const n=ke(e.canvasWidth,e.panelWidth,e.textAlign,e.bgFit),r=(e.canvasHeight-e.panelHeight)/2,a=Math.min(e.borderRadius,Math.min(e.panelWidth,e.panelHeight)/2);Ae(t,n,r,e.panelWidth,e.panelHeight,a),ze(t,{panelX:n,panelY:r,panelWidth:e.panelWidth,panelHeight:e.panelHeight,bgColor:e.bgColor,bgFillMode:e.bgFillMode,bgOpacity:e.bgOpacity,bgGradientStops:e.bgGradientStops,bgTextureImage:e.bgTextureImage,bgTextureFit:e.bgTextureFit,bgTextureFlipX:e.bgTextureFlipX,bgTextureFlipY:e.bgTextureFlipY}),e.borderColor&&e.borderWidth>0&&(t.lineWidth=e.borderWidth,t.strokeStyle=e.borderColor,t.stroke())}function ze(t,e){if(t.save(),t.globalAlpha=Math.max(0,Math.min(e.bgOpacity,1)),e.bgFillMode==="gradient"&&e.bgGradientStops&&e.bgGradientStops.length>1){const n=t.createLinearGradient(e.panelX,e.panelY,e.panelX+e.panelWidth,e.panelY+e.panelHeight);[...e.bgGradientStops].sort((r,a)=>r.position-a.position).forEach(r=>n.addColorStop(Math.max(0,Math.min(r.position,1)),r.color)),t.fillStyle=n,t.fill(),t.restore();return}if(e.bgTextureImage){t.clip(),Re(t,{image:e.bgTextureImage,x:e.panelX,y:e.panelY,width:e.panelWidth,height:e.panelHeight,fit:e.bgTextureFit,flipX:e.bgTextureFlipX,flipY:e.bgTextureFlipY}),t.restore();return}t.fillStyle=e.bgColor,t.fill(),t.restore()}function Re(t,e){const{image:n,x:r,y:a,width:i,height:l,fit:f,flipX:s,flipY:h}=e,o="naturalWidth"in n?n.naturalWidth:"videoWidth"in n?n.videoWidth:n.width,d="naturalHeight"in n?n.naturalHeight:"videoHeight"in n?n.videoHeight:n.height;let c=i,u=l,S=r,g=a;if(f!=="stretch"&&o>0&&d>0){const b=f==="cover"?Math.max(i/o,l/d):Math.min(i/o,l/d);c=o*b,u=d*b,S=r+(i-c)/2,g=a+(l-u)/2}t.save(),(s||h)&&(t.translate(s?r+i:0,h?a+l:0),t.scale(s?-1:1,h?-1:1),S=s?-(S-r)-c+r:S,g=h?-(g-a)-u+a:g),t.drawImage(n,S,g,c,u),t.restore()}function Ie(t,e,n,r,a,i){const l=a/72,f=Math.abs(l),s=1-Math.min(1,Math.abs(e)),h=Math.min(1,Math.abs(e)),o=r<=1?.5:n/(r-1),d=Math.sin(o*Math.PI*2-Math.PI/2),c=Math.sin(o*Math.PI*2.7-Math.PI/2)*(.65+o*.35),u=a*e*e,S=2*a*e/i,g={xOffset:0,yOffset:0,rotation:0,scaleX:1,scaleY:1};switch(t){case"arc":return{...g,yOffset:u,rotation:Math.atan(S)};case"arc-lower":return{...g,yOffset:u*.55,scaleY:Math.max(.2,1+l*e*e*.45)};case"arc-upper":return{...g,yOffset:-u*.55,scaleY:Math.max(.2,1-l*e*e*.45)};case"arch":return{...g,yOffset:u};case"bulge":return{...g,scaleY:Math.max(.2,1+l*s*.75)};case"shell-lower":return{...g,yOffset:a*.45*o*s,scaleY:Math.max(.2,1+l*o*s)};case"shell-upper":return{...g,yOffset:-a*.45*(1-o)*s,scaleY:Math.max(.2,1+l*(1-o)*s)};case"flag":return{...g,yOffset:a*.65*c,rotation:Math.atan(a/Math.max(i,1)*Math.cos(o*Math.PI*2.7)*1.6)};case"wave":return{...g,yOffset:a*.6*d,rotation:Math.atan(a/Math.max(i,1)*Math.cos(o*Math.PI*2)*1.4)};case"fish":return{...g,scaleX:Math.max(.25,1-f*h*.55),scaleY:Math.max(.2,1+l*s)};case"rise":return{...g,yOffset:a*e};case"fisheye":return{...g,yOffset:a*.18*e*s,scaleX:Math.max(.25,1+l*s*.7),scaleY:Math.max(.2,1+l*s*.7)};case"inflate":return{...g,scaleX:Math.max(.25,1+l*s*.6),scaleY:Math.max(.2,1+l*s*.6)};case"squeeze":return{...g,scaleY:Math.max(.2,1-l*s*.8)};case"twist":return{...g,yOffset:a*e,rotation:l*e*.45,scaleY:Math.max(.2,1+l*e*.25)};default:return g}}function X(t,e,n,r,a,i,l="arc",f=0){if(f!==0){Ee(t,e,n,r,a,i,l,f);return}Se(t,a),i==="fill"?t.fillText(e,n,r):t.strokeText(e,n,r),ye(t)}function Ee(t,e,n,r,a,i,l,f){const s=Array.from(e);if(s.length===0)return;const h=s.map(m=>t.measureText(m).width),o=h.reduce((m,y)=>m+y,0)+a*Math.max(0,s.length-1),d=t.textAlign,c=d==="right"?n-o:d==="center"?n-o/2:n,S=Math.max(-100,Math.min(f,100))/100*72,g=Math.max(o/2,1);let b=c;for(let m=0;m<s.length;m++){const y=s[m],v=h[m],C=b+v/2,W=(C-c-o/2)/g,O=Ie(l,W,m,s.length,S,g);t.save(),t.translate(C+O.xOffset,r+O.yOffset),t.rotate(O.rotation),t.scale(O.scaleX,O.scaleY),t.textAlign="center",i==="fill"?t.fillText(y,0,0):t.strokeText(y,0,0),t.restore(),b+=v+a}}function ge(t,e,n,r,a,i,l,f,s){const h=p(t,e,f),o=a==="center"?n-h/2:a==="right"?n-h:n,d=s==="underline"?l*.42:-l*.08,c=r+d;t.save(),t.strokeStyle=i,t.lineWidth=Math.max(2,l*.06),t.lineCap="round",t.beginPath(),t.moveTo(o,c),t.lineTo(o+h,c),t.stroke(),t.restore()}function De(t,e){for(let n=0;n<e.lines.length;n++){const r=e.lines[n],a=e.startY+n*e.lineHeight;for(const i of e.shadowLayers)t.save(),t.shadowColor=i.color,t.shadowBlur=i.blur,t.shadowOffsetX=i.offsetX??0,t.shadowOffsetY=i.offsetY??0,t.globalAlpha=i.opacity??1,t.fillStyle=e.color,X(t,r,e.textX,a,e.letterSpacingPx,"fill",e.bendPreset,e.bendStrength),t.restore();for(const i of e.strokeLayers)t.save(),t.lineJoin="round",t.miterLimit=2,t.lineWidth=i.width,t.strokeStyle=i.color,t.globalAlpha=i.opacity??1,X(t,r,e.textX,a,e.letterSpacingPx,"stroke",e.bendPreset,e.bendStrength),t.restore();t.save(),t.fillStyle=e.color,t.globalAlpha=1,X(t,r,e.textX,a,e.letterSpacingPx,"fill",e.bendPreset,e.bendStrength),t.restore(),e.underline&&ge(t,r,e.textX,a,e.textAlign,e.color,e.fontSize,e.letterSpacingPx,"underline"),e.strikethrough&&ge(t,r,e.textX,a,e.textAlign,e.color,e.fontSize,e.letterSpacingPx,"strikethrough")}}function $e(t,e){const n=Math.max(0,Math.min(e.intensity,1));if(n<=0)return;const r=Math.max(0,Math.min(e.range,1)),a=r*72,i=Math.max(-.5,Math.min(e.horizontalAngle,.5))*80,l=Math.max(-.5,Math.min(e.verticalAngle,.5))*80;for(let f=0;f<e.lines.length;f++){const s=e.startY+f*e.lineHeight;t.save(),t.globalAlpha=n,t.shadowColor=e.color,t.shadowBlur=a,t.shadowOffsetX=i,t.shadowOffsetY=l,e.style==="contoured"?(t.lineJoin="round",t.miterLimit=2,t.lineWidth=Math.max(2,r*42),t.strokeStyle=e.color,X(t,e.lines[f],e.textX,s,e.letterSpacingPx,"stroke",e.bendPreset,e.bendStrength)):(t.fillStyle=e.color,X(t,e.lines[f],e.textX,s,e.letterSpacingPx,"fill",e.bendPreset,e.bendStrength)),t.restore()}}function je(t,e){const n=Q(e.width,e.height),r=n.getContext("2d");r.clearRect(0,0,e.width,e.height),r.font=e.font,r.fillStyle="#ffffff",r.textAlign=e.textAlign,r.textBaseline="middle";for(let l=0;l<e.lines.length;l++)X(r,e.lines[l],e.textX,e.startY+l*e.lineHeight,e.letterSpacingPx,"fill",e.bendPreset,e.bendStrength);const a=Q(e.width,e.height),i=a.getContext("2d");i.clearRect(0,0,e.width,e.height),i.save(),i.globalAlpha=e.opacity,i.filter=e.blur>0?`blur(${e.blur}px)`:"none",i.drawImage(n,e.offsetX,e.offsetY),i.restore(),i.globalCompositeOperation="destination-in",i.drawImage(n,0,0),i.globalCompositeOperation="source-in",i.globalAlpha=e.opacity,i.fillStyle=e.color,i.fillRect(0,0,e.width,e.height),t.drawImage(a,0,0)}function qe(t){const{width:e,height:n,color:r,strokeLayers:a,strokeColor:i,strokeWidth:l,strokeOpacity:f,shadowLayers:s,innerShadow:h,glow:o,shadowColor:d,shadowBlur:c,shadowOffsetX:u,shadowOffsetY:S,shadowOpacity:g,textAlign:b,bgFillMode:m,bgOpacity:y,bgFit:v,bgAutoSize:C,bgWidth:W,bgHeight:O,bgGradientStops:L,bgTextureImage:F,bgTextureFit:I,bgTextureFlipX:E,bgTextureFlipY:D,underline:$,strikethrough:j,bendPreset:Y,bendStrength:k}=t;let{fontSize:A,bgColor:B}=t;const q=[...a??[],...i&&l>0?[{color:i,width:l,opacity:f}]:[]].filter(T=>T.width>0),G=[...s??[],...d&&(c>0||u!==0||S!==0)?[{color:d,blur:c,offsetX:u,offsetY:S,opacity:g}]:[]].filter(T=>T.blur>0||(T.offsetX??0)!==0||(T.offsetY??0)!==0);let P;const z=Q(e,n),M=z.getContext("2d");M.clearRect(0,0,e,n),M.fillStyle=r,M.textAlign=b,M.textBaseline="middle";const w=pe(M,t);if(A=w.fontSize,B!=="transparent"){const T=C===!0,_=ce(T?void 0:W,v==="text"||T?w.textBlockWidth:e,e),N=ce(T?void 0:O,v==="text"||T?w.textBlockHeight:n,n);Be(M,{canvasWidth:e,canvasHeight:n,textAlign:b,bgFit:v,panelWidth:_,panelHeight:N,bgColor:B,bgFillMode:m,bgOpacity:y,bgGradientStops:L,bgTextureImage:F,bgTextureFit:I,bgTextureFlipX:E,bgTextureFlipY:D,borderColor:t.borderColor,borderWidth:t.borderWidth,borderRadius:t.borderRadius})}return o&&$e(M,{lines:w.resolvedLines,textX:w.textX,startY:w.startY,lineHeight:w.lineHeight,letterSpacingPx:w.letterSpacingPx,bendPreset:Y,bendStrength:k,color:o.color,style:o.style,intensity:o.intensity??.5,range:o.range??.5,horizontalAngle:o.horizontalAngle??0,verticalAngle:o.verticalAngle??0}),De(M,{lines:w.resolvedLines,textX:w.textX,startY:w.startY,lineHeight:w.lineHeight,textAlign:b,color:r,fontSize:A,letterSpacingPx:w.letterSpacingPx,bendPreset:Y,bendStrength:k,shadowLayers:G,strokeLayers:q,underline:$,strikethrough:j}),h&&je(M,{width:e,height:n,font:M.font,lines:w.resolvedLines,textX:w.textX,startY:w.startY,lineHeight:w.lineHeight,letterSpacingPx:w.letterSpacingPx,bendPreset:Y,bendStrength:k,textAlign:b,color:h.color,opacity:h.opacity??1,blur:h.blur,offsetX:h.offsetX??0,offsetY:h.offsetY??0}),P=new Ce.CanvasTexture(z),P.needsUpdate=!0,P}function Ge(t,e){const{lines:n,color:r,strokeLayers:a,outlineEnabled:i,strokeColor:l,strokeWidth:f,strokeOpacity:s,shadowLayers:h,shadowEnabled:o,innerShadow:d,glow:c,shadowColor:u,shadowBlur:S,shadowOffsetX:g,shadowOffsetY:b,shadowOpacity:m,fontWeight:y,fontStyle:v,fontFamily:C,fontSize:W,textAlign:O,verticalAlign:L,overflow:F,resizeToFit:I,minFontSize:E,letterSpacing:D,lineSpacing:$,bgFillMode:j,bgOpacity:Y,bgFit:k,bgAutoSize:A,bgWidth:B,bgHeight:q,bgGradientStops:G,bgTextureFit:P,bgTextureFlipX:z,bgTextureFlipY:M,borderColor:w,borderWidth:T,borderRadius:_,padding:N,aspect:Z,resolution:U,underline:ee,strikethrough:te,bendPreset:ne,bendStrength:re}=t,ie=x.useMemo(()=>i===!1?[]:a,[i,a]),ae=x.useMemo(()=>o===!1?[]:h,[o,h]),le=void 0,oe=x.useMemo(()=>({text:e.text,lines:n,color:r,strokeLayers:ie,strokeColor:i===!1?void 0:l,strokeWidth:i===!1?0:f,strokeOpacity:s,shadowLayers:ae,innerShadow:d,glow:c,shadowColor:o===!1?void 0:u,shadowBlur:o===!1?0:S,shadowOffsetX:o===!1?0:g,shadowOffsetY:o===!1?0:b,shadowOpacity:m,fontWeight:y,fontStyle:v,fontFamily:C,fontSize:W,textAlign:O,verticalAlign:L,overflow:F,resizeToFit:I,minFontSize:E,letterSpacing:D,lineSpacing:$,bgColor:e.bgColor,bgFillMode:j,bgOpacity:Y,bgFit:k,bgAutoSize:A,bgWidth:B,bgHeight:q,bgGradientStops:G,bgTextureImage:le,bgTextureFit:P,bgTextureFlipX:z,bgTextureFlipY:M,borderColor:w,borderWidth:T,borderRadius:_,padding:N,height:U,width:Math.round(U*Math.max(Z,.1)),underline:ee,strikethrough:te,bendPreset:ne,bendStrength:re}),[e.text,e.bgColor,n,r,ie,i,l,f,s,ae,d,c,o,u,S,g,b,m,y,v,C,W,O,L,F,I,E,D,$,j,Y,k,A,B,q,G,le,P,z,M,w,T,_,N,Z,U,ee,te,ne,re]),se=x.useMemo(()=>qe(oe),[oe]);return ue(se),se}const _e=["color"];function Ne(t){const e=Te.useEditOverrides(t,_e),n={...Fe,...e},{text:r,bgColor:a,opacity:i,name:l,overlay:f=!0,position:s,rotation:h,scale:o,visible:d,renderOrder:c}=n,[u,S]=x.useState(null),[g,b]=x.useState(null),m=x.useRef(r);m.current!==r&&(m.current=r,u!==null&&S(null));const y=x.useRef(a);y.current!==a&&(y.current=a,g!==null&&b(null));const v=x.useRef(null),O=Ge(n,{text:u??r,bgColor:g??a});return x.useEffect(()=>{const L=v.current;if(L)return L.userData.setText=F=>S(F),L.userData.setBgColor=F=>b(F),()=>{delete L.userData.setText,delete L.userData.setBgColor}},[]),H.jsx(de,{ref:v,name:l,texture:O,overlay:f,opacity:i,position:s,rotation:h,scale:o,visible:d,renderOrder:c})}exports.ScreenSpaceUI=Le;exports.TextLabel=Ne;exports.useOwnedTexture=ue;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { default as defaultScreenImageUrl } from './assets/Default_square_image.png';
|
|
2
2
|
import { ScreenImageProps } from './types';
|
|
3
3
|
/**
|
|
4
|
-
* @editorElement screenImage transform.position transform.size transform.rotation
|
|
4
|
+
* @editorElement screenImage src opacity fit transform.position transform.size transform.rotation anchors.left anchors.right anchors.top anchors.bottom
|
|
5
5
|
*/
|
|
6
6
|
export declare function ScreenImage(rawProps: ScreenImageProps): import("react/jsx-runtime").JSX.Element | null;
|
|
7
7
|
export { defaultScreenImageUrl };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ScreenImageProps } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* A project file (`/images/...`) or an https URL; nothing else is loaded from an override.
|
|
4
|
+
* Browsers read `/\host`, and `/` then a tab or newline then `/host`, as `//host`, so a project
|
|
5
|
+
* path's second character must be an ordinary one.
|
|
6
|
+
*/
|
|
7
|
+
export declare const isLiveImageSrc: (v: unknown) => v is string;
|
|
8
|
+
/**
|
|
9
|
+
* The editor's live overrides merged into `props` (edit builds only). A `src` override
|
|
10
|
+
* applies only without a `source` prop, because `source` wins when both are set.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useScreenImageEditOverrides(props: ScreenImageProps): ScreenImageProps;
|
|
@@ -6,11 +6,29 @@ import { ScreenImageSource } from './source';
|
|
|
6
6
|
import type * as THREE from "three";
|
|
7
7
|
export type ScreenImageMaterialType = "unlit" | "standardPBR" | "matcap";
|
|
8
8
|
export type ScreenImageBlendMode = "normal" | "add" | "subtract" | "multiply" | "screen" | "lighten" | "darken" | "overlay" | "softLight" | "hardLight" | "difference" | "exclusion";
|
|
9
|
+
/**
|
|
10
|
+
* `ScreenAnchorEdges` with editor settings. Declared here, not on the shared type, so only
|
|
11
|
+
* ScreenImage lists its anchors in settings.json.
|
|
12
|
+
*/
|
|
13
|
+
export type ScreenImageAnchorEdges = ScreenAnchorEdges & {
|
|
14
|
+
/** @tweak unit=ratio min=-2 max=2 step=0.001 label="Left anchor" */
|
|
15
|
+
left?: number;
|
|
16
|
+
/** @tweak unit=ratio min=-2 max=2 step=0.001 label="Right anchor" */
|
|
17
|
+
right?: number;
|
|
18
|
+
/** @tweak unit=ratio min=-2 max=2 step=0.001 label="Top anchor" */
|
|
19
|
+
top?: number;
|
|
20
|
+
/** @tweak unit=ratio min=-2 max=2 step=0.001 label="Bottom anchor" */
|
|
21
|
+
bottom?: number;
|
|
22
|
+
};
|
|
9
23
|
export type ScreenImageProps = {
|
|
10
24
|
name?: string;
|
|
11
25
|
source?: ScreenImageSource;
|
|
26
|
+
/**
|
|
27
|
+
* Image URL or project path. Ignored while `source` is set.
|
|
28
|
+
* @tweak asset accept=image overriddenBy=source
|
|
29
|
+
*/
|
|
12
30
|
src?: string;
|
|
13
|
-
anchors?:
|
|
31
|
+
anchors?: ScreenImageAnchorEdges;
|
|
14
32
|
coordinateSpace?: ScreenCoordinateSpace;
|
|
15
33
|
canvasSize?: ScreenCanvasSize;
|
|
16
34
|
position?: [number, number];
|
|
@@ -21,7 +39,7 @@ export type ScreenImageProps = {
|
|
|
21
39
|
transform?: Partial<ScreenTransform2DSettings>;
|
|
22
40
|
onScreenTransformChange?: (next: ScreenTransform2DSettings) => void;
|
|
23
41
|
transformGuideLayer?: ScreenTransformGuideLayer;
|
|
24
|
-
/** @tweak label=Fit */
|
|
42
|
+
/** @tweak label=Fit overriddenBy=stretchMode */
|
|
25
43
|
fit?: ScreenImageFit;
|
|
26
44
|
stretchMode?: ScreenImageStretchMode;
|
|
27
45
|
materialType?: ScreenImageMaterialType;
|
|
@@ -4,6 +4,6 @@ export { resolveScreenTextAnchors } from './utils/ScreenTextHelpers';
|
|
|
4
4
|
export { resolveScreenTextBendProps, resolveScreenTextLayoutTexture, } from './utils/ScreenTextMappings';
|
|
5
5
|
export type { ScreenTextBendSettings, ScreenTextProps, ScreenTextVerticalAlign } from './types';
|
|
6
6
|
/**
|
|
7
|
-
* @editorElement screenText fontSize color screenTransform.position screenTransform.size screenTransform.rotation
|
|
7
|
+
* @editorElement screenText text fontSize color screenTransform.position screenTransform.size screenTransform.rotation
|
|
8
8
|
*/
|
|
9
9
|
export declare function ScreenText(rawProps: ScreenTextProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ScreenTextProps } from './types';
|
|
2
|
+
/** Props the visual editor can show live while a change is unsaved (edit builds only). */
|
|
3
|
+
export declare const SCREEN_TEXT_LIVE_EDITABLE: readonly ["text", "color", "fontSize", "screenTransform.position", "screenTransform.size", "screenTransform.rotation"];
|
|
4
|
+
export declare const isLiveText: (v: unknown) => v is string;
|
|
5
|
+
/** A `text` override applies only without a `lines` prop, because `lines` wins when both are set. */
|
|
6
|
+
export declare function useScreenTextEditOverrides(props: ScreenTextProps): ScreenTextProps;
|
|
@@ -50,7 +50,10 @@ export type TextGradientStop = {
|
|
|
50
50
|
* the text is allowed to clip.
|
|
51
51
|
*/
|
|
52
52
|
export type TextLabelProps = {
|
|
53
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* The text to render. Required.
|
|
55
|
+
* @tweak text maxLength=500 multiline=true overriddenBy=lines
|
|
56
|
+
*/
|
|
54
57
|
text: string;
|
|
55
58
|
/** Optional precomputed lines. When provided, these are rendered directly without word wrapping. */
|
|
56
59
|
lines?: string[];
|