@nookly/pebble-icons 0.1.0 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nookly/pebble-icons",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Soft solid icons for React, drawn as SVG.",
5
5
  "keywords": [
6
6
  "pebble",
@@ -19,7 +19,9 @@
19
19
  },
20
20
  "license": "MIT",
21
21
  "type": "module",
22
- "sideEffects": false,
22
+ "sideEffects": [
23
+ "*.css"
24
+ ],
23
25
  "exports": {
24
26
  ".": {
25
27
  "types": "./index.d.ts",
@@ -28,7 +30,8 @@
28
30
  "./icons/*": {
29
31
  "types": "./icons/*.d.ts",
30
32
  "default": "./icons/*.js"
31
- }
33
+ },
34
+ "./motion.css": "./motion.css"
32
35
  },
33
36
  "peerDependencies": {
34
37
  "react": "^18.0.0 || ^19.0.0"
package/parts.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { ReactNode } from "react";
1
2
  export declare const AREA: {
2
3
  x: number;
3
4
  y: number;
@@ -29,19 +30,28 @@ export type Part = ({
29
30
  transform?: string;
30
31
  }) & {
31
32
  opacity?: number;
33
+ move?: string;
32
34
  };
33
35
  export declare const rect: (x: number, y: number, width: number, height: number, radius: number, transform?: string) => Part;
34
36
  export declare const circle: (cx: number, cy: number, r: number, transform?: string) => Part;
35
37
  export declare const path: (d: string, transform?: string) => Part;
36
38
  export declare const line: (d: string, width: number, transform?: string) => Part;
37
39
  export declare const sheer: (opacity: number, part: Part) => Part;
40
+ export declare const moving: (move: string, parts: Part[]) => Part[];
41
+ export declare const Movable: ({ icon, move, children, }: {
42
+ icon: string;
43
+ move: string | undefined;
44
+ children: ReactNode;
45
+ }) => string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").JSX.Element | null | undefined;
46
+ export declare const layered: (layer: string, parts: Part[]) => Part[];
38
47
  export interface Paint {
39
48
  fill?: string;
40
49
  fillOpacity?: number;
41
50
  stroke?: string;
42
51
  strokeWidth?: number;
43
52
  }
44
- export declare function Parts({ parts, paint, grow, }: {
53
+ export declare function Parts({ icon, parts, paint, grow, }: {
54
+ icon: string;
45
55
  parts: readonly Part[];
46
56
  paint: Paint;
47
57
  grow?: number;
package/parts.js CHANGED
@@ -1,6 +1,4 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- /// The few shapes icons are made of, as data, so one drawing can be painted more than once: as a
3
- /// shape, as a mask that cuts through other shapes, and as an outline.
4
2
  /// The area masks work on, wide enough for shapes that reach past the grid.
5
3
  export const AREA = { x: -5, y: -5, width: 34, height: 34 };
6
4
  export const rect = (x, y, width, height, radius, transform) => ({ kind: "rect", x, y, width, height, radius, transform });
@@ -20,6 +18,29 @@ export const line = (d, width, transform) => ({
20
18
  });
21
19
  /// The same part as a sheet of its own.
22
20
  export const sheer = (opacity, part) => ({ ...part, opacity });
21
+ /// The same shapes as one part that can move, named for `motion.css`.
22
+ export const moving = (move, parts) => parts.map((part) => ({ ...part, move }));
23
+ /// A group around a part that moves. Every copy of the part gets one, in the masks too, so
24
+ /// they all move together. The shape keeps its own transform inside.
25
+ ///
26
+ /// `motion.css` finds a drawing's part by the class: a browser looks a class up at once, where
27
+ /// it would try hundreds of attribute rules on every part.
28
+ export const Movable = ({ icon, move, children, }) => move === undefined ? (children) : (_jsx("g", { "data-move": move, className: `pebble-${icon}__${move}`, children: children }));
29
+ /// The parts of one layer, each named after the layer unless it has a name of its own, so
30
+ /// every part of a drawing can move.
31
+ export const layered = (layer, parts) => parts.map((part) => (part.move === undefined ? { ...part, move: layer } : part));
32
+ /// Parts that lie next to each other and move as one, grouped.
33
+ function together(parts) {
34
+ const runs = [];
35
+ for (const part of parts) {
36
+ const last = runs[runs.length - 1];
37
+ if (last && last[0].move === part.move)
38
+ last.push(part);
39
+ else
40
+ runs.push([part]);
41
+ }
42
+ return runs;
43
+ }
23
44
  function Drawn({ part, paint, grow }) {
24
45
  const { fill, fillOpacity, stroke, strokeWidth } = paint;
25
46
  const { transform } = part;
@@ -32,14 +53,19 @@ function Drawn({ part, paint, grow }) {
32
53
  case "path":
33
54
  return _jsx("path", { d: part.d, ...shape });
34
55
  case "line":
35
- return (_jsx("path", { d: part.d, fill: "none", stroke: stroke ?? fill, strokeWidth: part.width + grow, strokeLinecap: "round", strokeLinejoin: "round", transform: transform }));
56
+ return (_jsx("path", { d: part.d, fill: "none", stroke: stroke ?? fill, strokeWidth: part.width + grow, strokeLinecap: "round", strokeLinejoin: "round", transform: transform,
57
+ // So a line that draws itself can be told how far along it is, from 0 to 1.
58
+ pathLength: part.move === undefined ? undefined : 1 }));
36
59
  }
37
60
  }
38
61
  /// Parts in one paint. A line is a stroke in the paint's `stroke`, or else its `fill`; `grow`
39
- /// makes it that much wider, for a mask that has to reach past an outline.
40
- export function Parts({ parts, paint, grow = 0, }) {
41
- return parts.map((part, at) => (
42
- // A drawing never changes, so a part's place in it is its identity.
62
+ /// makes it that much wider, for a mask that has to reach past an outline. A part that can
63
+ /// move sits in a group of its own.
64
+ export function Parts({ icon, parts, paint, grow = 0, }) {
65
+ return together(parts).map((run, index) => (
66
+ // A drawing never changes, so a shape's place in it is its identity.
43
67
  // oxlint-disable-next-line react/no-array-index-key
44
- _jsx(Drawn, { part: part, paint: paint, grow: grow }, at)));
68
+ _jsx(Movable, { icon: icon, move: run[0].move, children: run.map((part, at) => (
69
+ // oxlint-disable-next-line react/no-array-index-key
70
+ _jsx(Drawn, { part: part, paint: paint, grow: grow }, at))) }, index)));
45
71
  }