craft-library 0.1.2 → 0.1.3

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/README.md CHANGED
@@ -44,7 +44,7 @@ import { LikeButton } from 'craft-library';
44
44
 
45
45
  ## Magnetic icon
46
46
 
47
- A round search button with a brushed-metal rim, for dark backgrounds. Near the cursor the rim acts like metal near a strong magnet: the disc is drawn toward the pointer, the rim creases, the whole ring frays out of round and loses small voxels of metal, its tip cracks into shards, and the voxels fly off to the pointer.
47
+ A round search button with a brushed-metal rim, for dark backgrounds. Near the cursor the rim acts like metal near a strong magnet: the disc is drawn toward the pointer, the rim creases and trembles and, where it is pulled, comes apart in small voxels of metal; its tip cracks into shards and the voxels fly off to the pointer.
48
48
 
49
49
  ```jsx
50
50
  import { MagneticIcon } from 'craft-library';
package/dist/craft.js CHANGED
@@ -436,7 +436,7 @@
436
436
  var PULL = 15, FALL = 1.1;
437
437
  var BODY = 0.3, SHIFT = 0.14;
438
438
  var JAG = 0.18;
439
- var FRAY = 2.6, CHIPS = 64;
439
+ var FRAY = 1.6, CHIPS = 90;
440
440
  var DENT = 3.5;
441
441
  var RATE = 90, MAXDUST = 90;
442
442
  var ROOM = 46;
@@ -481,7 +481,7 @@
481
481
  return clamp((Math.abs(m.d) + 3 * m.heat) / PULL, 0, 1);
482
482
  }
483
483
  function damage(m, t) {
484
- return clamp((Math.abs(m.d) + 3 * m.heat) / 9, 0, 1) * (0.5 + 0.5 * bell(wrap(t - m.a), 1.3));
484
+ return clamp((Math.abs(m.d) + 3 * m.heat) / 9, 0, 1) * bell(wrap(t - m.a), 0.7);
485
485
  }
486
486
  function rimPath(m, now) {
487
487
  var pts = [], strain = strainOf(m), i, t, r, env, sharp, fray, n, p, a, b, c, e;
@@ -682,14 +682,14 @@
682
682
  g.restore();
683
683
  }
684
684
  function chips(m, now) {
685
- var t = m.t;
685
+ var t = m.t, f = crack(m)[0];
686
686
  m.chips.forEach(function(c, k) {
687
687
  var o = clamp((damage(m, c.a) + 0.08 * tremble(300 + k, now) - c.at) / 0.12, 0, 1), z, r, x, y, dx, dy, l;
688
688
  if (o < 0.02) o = 0;
689
689
  if (!o && !c.open) return;
690
690
  c.open = o;
691
691
  z = c.s * o;
692
- r = radius(m, c.a) + c.o;
692
+ r = Math.min(radius(m, c.a), f) + c.o;
693
693
  x = m.cx + r * Math.cos(c.a);
694
694
  y = m.cy + r * Math.sin(c.a);
695
695
  c.el.setAttribute("x", n2(x - z / 2));
package/dist/magnet.js CHANGED
@@ -8,9 +8,9 @@ function engine() {
8
8
  const window = {};
9
9
  // Magnetic icon · Craft Library, by Sara Lobo
10
10
  // Every .mag on the page reads the pointer and its rim follows it while it is near: the disc is drawn toward it, the
11
- // strained rim creases and trembles, the rest of the ring frays out of round and loses voxels, the tip cracks into
12
- // shards, and the voxels fly to the pointer. Let go, and the rim springs back with a wobble, closing up as the loose
13
- // voxels return to it. Pairs with magnet.css.
11
+ // strained rim creases, trembles and comes apart where it is pulled, the tip cracks into shards, and voxels fly to
12
+ // the pointer. Let go, and the rim springs back with a wobble, closing up as the loose voxels return to it. Pairs with
13
+ // magnet.css.
14
14
  // Buttons added later: magnetize(root). To steer one without a mouse (a demo, a tour): magnetPoint(button, x, y) with
15
15
  // a point on screen, and magnetPoint(button, null) to hand it back to the pointer.
16
16
  (function () {
@@ -19,7 +19,7 @@ function engine() {
19
19
  var PULL = 15, FALL = 1.1; // the furthest the rim reaches out, and how fast the pull drops with distance
20
20
  var BODY = 0.3, SHIFT = 0.14; // how much of the disc goes with the tip, and how far the disc itself is drawn
21
21
  var JAG = 0.18; // how deep the strained rim creases
22
- var FRAY = 2.6, CHIPS = 64; // how far the rest of the ring frays out of round, and how many voxels can fall out of it
22
+ var FRAY = 1.6, CHIPS = 90; // how far the pulled stretch of the rim frays, and how many voxels can fall out of the ring
23
23
  var DENT = 3.5; // the furthest the rim is drawn in while the pointer is over the button
24
24
  var RATE = 90, MAXDUST = 90; // voxels shed per second at full pull, and at most at once
25
25
  var ROOM = 46; // room for the shards and voxels on every side of the button (matches .mag-dust)
@@ -47,14 +47,14 @@ function engine() {
47
47
  return R + (d > 0 ? d * (spike(dt, width(m)) + BODY * bell(dt, 1)) : d * bell(dt, 0.7)) - 0.12 * d * bell(wrap(dt - Math.PI), 1.3);
48
48
  }
49
49
 
50
- // how hard the field strains the metal (0 at rest, 1 at a full pull), and how worn the ring is at angle t: wear
51
- // builds faster than the strain, so a middling pull already marks the whole ring; it is worst toward the pull, but
52
- // the far side gives too, so the ring reads as coming apart, not only its tip
50
+ // how hard the field strains the metal (0 at rest, 1 at a full pull), and how worn the rim is at angle t: only where
51
+ // the magnet pulls, beside the shards, fading out within about a quarter turn either side; the rest of the ring
52
+ // stays whole. Wear builds faster than the strain, so a middling pull already marks it
53
53
  function strainOf(m) { return clamp((Math.abs(m.d) + 3 * m.heat) / PULL, 0, 1); }
54
- function damage(m, t) { return clamp((Math.abs(m.d) + 3 * m.heat) / 9, 0, 1) * (0.5 + 0.5 * bell(wrap(t - m.a), 1.3)); }
54
+ function damage(m, t) { return clamp((Math.abs(m.d) + 3 * m.heat) / 9, 0, 1) * bell(wrap(t - m.a), 0.7); }
55
55
 
56
56
  // the rim as one closed curve: smooth where it is calm (Catmull-Rom turned into cubic Béziers), creased into straight,
57
- // trembling facets where the magnet strains it, and frayed out of round, in short crooked facets, around the rest
57
+ // trembling facets where the magnet strains it, and frayed into short crooked facets on either side of them
58
58
  function rimPath(m, now) {
59
59
  var pts = [], strain = strainOf(m), i, t, r, env, sharp, fray, n, p, a, b, c, e;
60
60
  for (i = 0; i < N; i++) {
@@ -211,17 +211,18 @@ function engine() {
211
211
  g.restore();
212
212
  }
213
213
 
214
- // the voxels falling out of the ring: holes in the rim's mask, each opening once the metal is broken enough where it
215
- // sits (and flickering at the edge of breaking). The piece that falls out flies to the magnet; as the ring heals,
216
- // the holes close again
214
+ // the voxels falling out of the rim where it's pulled: holes in the rim's mask, each opening once the metal is worn
215
+ // enough where it sits (and flickering at the edge of breaking), always on the rim you can see: past the crack line,
216
+ // where the shards take over, that's the crack line itself. The piece that falls out flies to the magnet; as the
217
+ // rim heals, the holes close again
217
218
  function chips(m, now) {
218
- var t = m.t;
219
+ var t = m.t, f = crack(m)[0];
219
220
  m.chips.forEach(function (c, k) {
220
221
  var o = clamp((damage(m, c.a) + 0.08 * tremble(300 + k, now) - c.at) / 0.12, 0, 1), z, r, x, y, dx, dy, l;
221
222
  if (o < 0.02) o = 0; // closed means fully closed: no sliver left in the mask
222
223
  if (!o && !c.open) return;
223
224
  c.open = o;
224
- z = c.s * o; r = radius(m, c.a) + c.o; x = m.cx + r * Math.cos(c.a); y = m.cy + r * Math.sin(c.a);
225
+ z = c.s * o; r = Math.min(radius(m, c.a), f) + c.o; x = m.cx + r * Math.cos(c.a); y = m.cy + r * Math.sin(c.a);
225
226
  c.el.setAttribute('x', n2(x - z / 2)); c.el.setAttribute('y', n2(y - z / 2));
226
227
  c.el.setAttribute('width', n2(z)); c.el.setAttribute('height', n2(z));
227
228
  if (o < 0.2) c.gone = false;
@@ -295,7 +296,7 @@ function engine() {
295
296
  cv.className = 'mag-dust';
296
297
  cv.setAttribute('aria-hidden', 'true');
297
298
  el.insertBefore(cv, icon);
298
- // the voxels that can fall out of the ring: squares in the rim's mask, closed until the metal strains (see chips()).
299
+ // the voxels that can fall out of the rim: squares in its mask, closed until the metal wears (see chips()).
299
300
  // Each sits at its own spot round the ring, mostly biting the rim from outside, and gives way at its own strain
300
301
  var mask = svg.querySelector('mask'), holes = [], k, q;
301
302
  for (k = 0; mask && k < CHIPS; k++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "craft-library",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Craft Library by Sara Lobo: a liquid glass nav bar, a bursting heart and a magnetic icon, for React or plain HTML",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",