Skip to content

react-3d-mockups v0.2.0

Latest

Choose a tag to compare

@github-actions github-actions released this 15 Oct 00:04
76f3e62

Added

  • Experimental: screens that take input (experimentalScreenInput). On MockupCanvas and every one-liner mockup. Clicks, hover, wheel and touch scrolling, typing and focus reach the screen content as they do on the page, iframes included. Each screen's DOM stacks above the canvas and is clipped every frame (clip-path: path(evenodd, …)) to the part of it no hardware covers, traced from the pixels the canvas leaves transparent for it, so a laptop's base still hides the bottom of its display from below. Screens last took input by raycasting, which could only show or hide a whole screen; this clips per pixel instead. A tap is the content's and a drag still turns the model, unless the content claims it (form controls, data-mockup-no-rotate, or a pointer it captures with setPointerCapture) or screenDrag={false} - on the mockup, or on one slot - leaves every drag on the screen to the content. It costs a synchronous canvas readback per screen per drawn frame and about 2 KB gzip, loaded only once a screen takes input, and the screens join the accessibility tree. The name says it: it may change or go away in any release. Try it at /harness/screen-input on the docs site.

  • CreditCardMockup and CreditCard: a payment card with real embossing. An ISO/IEC 7810 ID-1 card (85.60×53.98×0.76 mm, 3.18 mm corners) with live full-bleed front and back faces, measured under the new creditCard kind, checked against photographs of real cards. The print sits under a gloss laminate that picks up the studio lights as the card turns (finish="matte" for soft-touch), round a white core at the cut edge (edgeColor). Over the print stand a 13×11.4 mm EMV contact plate, chip="gold" or "silver", etched with its contacts and set in its milled cavity over the ISO/IEC 7816-2 contact field; and the number, name and expiry embossed as raised geometry up to 0.46 mm high - flat crests carrying silver, gold or any colour of foil tipping (or 'none', which shades the print instead) on shoulders that slope into the print. The number is in a Farrington 7B-style face centred 21.42 mm above the bottom edge, the name and expiry in the ISO/IEC 7811-1 name-and-address area with a printed "VALID THRU" legend, and the back carries their mirrored, debossed impressions beside the magnetic stripe and the signature panel. emboss="flat" prints the lines in a thin line instead, as most new cards do, and emboss={false}, chip={false}, stripe and signature turn their piece off. The lettering is a stroke font in the core (STROKE_FONT, layoutStrokeText, normalizeStrokeText): no font files and nothing to download. Accented letters are transliterated (José embosses as JOSE); characters it still has no glyph for are dropped with a one-time development warning.

  • Device lifecycle, and a way to retire old models. Every device variant now belongs to a product line in DEVICE_LINEUP (react-3d-mockups/core), with the month it was announced, and deviceLifecycle(kind, variant) says where it stands:

    • current: the newest model in its line;
    • superseded: a newer model in its line is in the catalog. Today that is the iPhone 17 Pro and Pro Max, the Galaxy Z Fold 7 and Z Flip 7, Apple Watch Series 11 and Galaxy Watch 8. Superseded models are fully supported;
    • deprecated: scheduled for removal, with the release that removes it.

    A deprecated model logs one development warning naming its replacement. A removed one throws an error that points to its replacement, through REMOVED_DEVICES. Nothing is deprecated yet. CONTRIBUTING.md has the deprecation and removal process. The docs sidebar and gallery now show the newest model of each line, with the older ones one click away.

  • TVSetProps and DOOHTotemSize, named after their components. TVProps and DoohTotemSize stay as aliases. MockupRegions<K> is the region map mockupInfo(kind) returns for a kind.

  • More warnings in development, each logged once:

    • a mockup whose container has no height, which leaves it 0 px tall and invisible;
    • a color that is a colorway id of another variant (color="coralred" on a Flip 8), naming the variants that have it;
    • a slot of another mockup (<AFrameSignMockup.Back> inside <BookMockup>), which used to land on any region with the same name and is now ignored;
    • a canvas whose WebGL context the browser dropped (see below).

Changed (breaking)

  • BusMockup's curb-side ad is a queen-size panel, 586×200 by default (was 960×200). The curb side used to mirror the street side's king-size panel, which ran across the rear door, so the door's glass drew over the left third of the art. The queen panel sits between the rear door and the front wheel arch, at the street side's print density. Lay curb-side art out for 586×200, or use coverage="full", which is unchanged.
  • catalog.json is version 2. The Fold and Flip rows carry openAngle (version 1 named a nonexistent open prop, so every folded row measured the open screen), the iPhone Duo is enumerated open and folded in both orientations, and the TV by variant: 95 rows. Code that filtered on props.open should filter on props.openAngle.
  • mockupInfo(kind).regions is typed per kind. mockupInfo('book') .regions.cover.px typechecks, a misspelt region name is a type error, and a region with several surfaces (the van's licensePlate) is an array. Code that narrowed the old RegionInfo | RegionInfo[] union by hand may need the narrowing removed.
  • XMockup.info() and XMockup.regions are no longer optional on the built-in mockups, and info() requires its argument where the kind needs a size (CustomPanelMockup.info({ size })); calling it without one used to typecheck and then throw.

Changed

  • Importing one mockup ships only that mockup. The ESM build is one file per module instead of one bundle, so "sideEffects": false lets an app's bundler drop everything an import does not reach. Importing BookMockup used to ship the whole library (~135 KB gzip); it is now about 15 KB, and a device about 60 KB, most of it the CSG engine the devices share. The docs' import-cost table is measured from the published build.
  • The main entry works in a Server Component. Only the component modules carry 'use client', so mockupInfo, the colorways and the specs import from react-3d-mockups into server code as well as from react-3d-mockups/core. They used to be client references the server could not call.
  • gl, onCreated, dpr and pauseWhenOffscreen are mockup props. They always reached the canvas at runtime, but TypeScript rejected them on a *Mockup.
  • BusShelterMockup and MailerBoxMockup frame the surface your content is on. The shelter's camera used to face the inner poster, so bare children were on the face turned away; the mailer's looked at its lid edge on. Both now show the primary region at the default pose.
  • MailerBoxMockup prints every panel at one density, resolution being the lid's width, and mockupInfo reports the 520 px the lid renders (it said 513).
  • Sourcemaps no longer embed the sources, which were 4.5 MB of the package's 7.7 MB.

Fixed

  • An unknown variant throws an error that names it. A misspelt variant on a device component, or passed to mockupInfo, used to throw a TypeError from inside the scene or the metrics resolver. It now throws unknown variant "…" and lists the variants that exist. The TV, which used to fall back to its default design, does the same.
  • No console errors when a screen mounts. Every screen logged "Attempted to synchronously unmount a root while React was already rendering" in development, twice under StrictMode, because drei's <Html> unmounted its React root inside React's commit. Screens now mount through their own portal (adapted from drei's <Html>), which gives every mount its own root and unmounts an outgoing one after the commit.
  • A canvas whose WebGL context is lost comes back. Browsers drop the oldest contexts when a page holds too many; such a canvas stayed blank. It now shows an empty placeholder and starts a fresh renderer the next time it scrolls into view.
  • A bad millimetre size fails by name. CustomPanel and CustomBox without a size, or any object given a zero, negative or non-finite dimension, used to render nothing and measure Infinity. They throw an error naming the component and showing a valid size.
  • A foldable's half pane reports the whole display to useSurface(), not the fraction of it that half shows, so content laid out from it spans the fold correctly while the device is partly open.

react-3d-mockups@0.2.0 on npm