- Jump To … +
  ./source/core/animation-loop.js ./source/core/display-cycle.js ./source/core/document-root-elements.js ./source/core/document.js ./source/core/events.js ./source/core/init.js ./source/core/library.js ./source/core/random-seed.js ./source/core/shared-vars.js ./source/core/snippets.js ./source/core/system-flags.js ./source/core/user-interaction.js ./source/core/utilities.js ./source/factory/action.js ./source/factory/anchor.js ./source/factory/animation.js ./source/factory/array-pool.js ./source/factory/bezier.js ./source/factory/block.js ./source/factory/canvas.js ./source/factory/cell-fragment.js ./source/factory/cell.js ./source/factory/cog.js ./source/factory/color.js ./source/factory/conic-gradient.js ./source/factory/coordinate.js ./source/factory/crescent.js ./source/factory/drag-zone.js ./source/factory/element.js ./source/factory/emitter.js ./source/factory/filter-engine-bluenoise-data.js ./source/factory/filter-engine.js ./source/factory/filter.js ./source/factory/font-attributes.js ./source/factory/gradient.js ./source/factory/grid.js ./source/factory/group.js ./source/factory/image-asset.js ./source/factory/keyboard-zone.js ./source/factory/line-spiral.js ./source/factory/line.js ./source/factory/loom.js ./source/factory/mesh.js ./source/factory/net.js ./source/factory/noise-asset.js ./source/factory/observe-update.js ./source/factory/oval.js ./source/factory/palette.js ./source/factory/particle-force.js ./source/factory/particle-history.js ./source/factory/particle-spring.js ./source/factory/particle-world.js ./source/factory/particle.js ./source/factory/pattern.js ./source/factory/phrase.js ./source/factory/picture.js ./source/factory/polygon.js ./source/factory/polyline.js ./source/factory/quadratic.js ./source/factory/quaternion.js ./source/factory/radial-gradient.js ./source/factory/raw-asset.js ./source/factory/reaction-diffusion-asset.js ./source/factory/rectangle.js ./source/factory/render-animation.js ./source/factory/shape.js ./source/factory/spiral.js ./source/factory/sprite-asset.js ./source/factory/stack.js ./source/factory/star.js ./source/factory/state.js ./source/factory/tetragon.js ./source/factory/ticker.js ./source/factory/tracer.js ./source/factory/tween.js ./source/factory/unstacked-element.js ./source/factory/vector.js ./source/factory/video-asset.js ./source/factory/wheel.js ./source/mixin/anchor.js ./source/mixin/asset-advanced-functionality.js ./source/mixin/asset-consumer.js ./source/mixin/asset.js ./source/mixin/base.js ./source/mixin/cascade.js ./source/mixin/cell-key-functions.js ./source/mixin/delta.js ./source/mixin/display-shape.js ./source/mixin/dom.js ./source/mixin/entity.js ./source/mixin/filter.js ./source/mixin/mimic.js ./source/mixin/path.js ./source/mixin/pattern.js ./source/mixin/pivot.js ./source/mixin/position.js ./source/mixin/shape-basic.js ./source/mixin/shape-curve.js ./source/mixin/shape-path-calculation.js ./source/mixin/styles.js ./source/mixin/tween.js

- §

  # Block factory

  Block entitys are rectangles rendered onto a DOM <canvas> element using the Canvas API’s Path2D interface - specifically the `rect` method.

  - Positioning and dimensions functionality for the Block is supplied by the position mixin, while rendering functionality comes from the entity mixin.
  - Blocks can use CSS color Strings for their fillStyle and strokeStyle values, alongside Gradient, RadialGradient, Color and Pattern objects.
  - They will also accept Filter objects.
  - They can use Anchor objects for user navigation.
  - They can be rendered to the canvas by including them in a Cell object’s Group.
  - They can be animated directly, or using delta animation, or act as the target for Tween animations.
  - Blocks can be cloned, and killed.
- §

  #### Demos:

  - Canvas-001 - Block and Wheel entitys (make, clone, method); drag and drop block and wheel entitys
  - Canvas-005 - Cell-locked, and Entity-locked, gradients; animating gradients by delta, and by tween
  - Canvas-007 - Apply filters at the entity, group and cell level
  - Canvas-009 - Pattern styles; Entity web link anchors; Dynamic accessibility
  - Packets-001 - Save and load Scrawl-canvas entity using text packets
- §

  #### Imports

      import { constructors } from '../core/library.js';
      import { doCreate, Ωempty } from '../core/utilities.js';

      import { ENTITY, T_BLOCK } from '../core/shared-vars.js';

      import baseMix from '../mixin/base.js';
      import entityMix from '../mixin/entity.js';

- §

  #### Block constructor

      const Block = function (items = Ωempty) {

          this.entityInit(items);

          if (!items.dimensions) {

              if (!items.width) this.currentDimensions[0] = this.dimensions[0] = 10;
              if (!items.height) this.currentDimensions[1] = this.dimensions[1] = 10;
          }
          return this;
      };

- §

  #### Block prototype

      const P = Block.prototype = doCreate();
      P.type = T_BLOCK;
      P.lib = ENTITY;
      P.isArtefact = true;
      P.isAsset = false;

- §

  #### Mixins

  - base
  - entity

      baseMix(P);
      entityMix(P);

- §

  #### Block attributes

  - Attributes defined in the base mixin: name.
  - Attributes defined in the position mixin: group, visibility, order, calculateOrder, stampOrder, start, startX, startY, handle, handleX, handleY, offset, offsetX, offsetY, dimensions, width, height, pivoted, mimicked, lockTo, lockXTo, lockYTo, scale, roll, noUserInteraction, noPositionDependencies, noCanvasEngineUpdates, noFilters, noPathUpdates, purge, bringToFrontOnDrag.
  - Attributes defined in the delta mixin: delta, noDeltaUpdates.
  - Attributes defined in the pivot mixin: pivot, pivotCorner, addPivotHandle, addPivotOffset, addPivotRotation.
  - Attributes defined in the mimic mixin: mimic, useMimicDimensions, useMimicScale, useMimicStart, useMimicHandle, useMimicOffset, useMimicRotation, useMimicFlip, addOwnDimensionsToMimic, addOwnScaleToMimic, addOwnStartToMimic, addOwnHandleToMimic, addOwnOffsetToMimic, addOwnRotationToMimic.
  - Attributes defined in the path mixin: path, pathPosition, addPathHandle, addPathOffset, addPathRotation, constantPathSpeed.
  - Attributes defined in the entity mixin: method, pathObject, winding, flipReverse, flipUpend, scaleOutline, lockFillStyleToEntity, lockStrokeStyleToEntity, onEnter, onLeave, onDown, onUp, fillStyle, strokeStyle, globalAlpha, globalCompositeOperation, lineWidth, lineCap, lineJoin, lineDash, lineDashOffset, miterLimit, shadowOffsetX, shadowOffsetY, shadowBlur, shadowColor, filter.
  - Attributes defined in the anchor mixin: anchor.
  - Attributes defined in the filter mixin: filters, isStencil.

  No additional attributes required beyond those supplied by the mixins

- §

  #### Packet management

  No additional packet functionality required

- §

  #### Clone management

  No additional clone functionality required

- §

  #### Kill management

  No additional kill functionality required

- §

  #### Get, Set, deltaSet

  No additional functionality required

- §

  #### Prototype functions

- §

  `cleanPathObject` - Calculate the Block entity’s Path2D object

      P.cleanPathObject = function () {

          this.dirtyPathObject = false;

          if (!this.noPathUpdates || !this.pathObject) {

              const p = this.pathObject = new Path2D();

              const handle = this.currentStampHandlePosition,
                  scale = this.currentScale,
                  dims = this.currentDimensions;

              const x = -handle[0] * scale,
                  y = -handle[1] * scale,
                  w = dims[0] * scale,
                  h = dims[1] * scale;

              p.rect(x, y, w, h);
          }
      };

- §

  #### Factory

      scrawl.makeBlock({

          name: 'myblock-fill',
          width: 100,
          height: 100,
          startX: 25,
          startY: 25,

          fillStyle: 'green',
          strokeStyle: 'gold',

          lineWidth: 6,
          lineJoin: 'round',
          shadowOffsetX: 4,
          shadowOffsetY: 4,
          shadowBlur: 2,
          shadowColor: 'black',

      }).clone({

          name: 'myblock-draw',
          startX: 175,

          method: 'draw',
          sharedState: true,
      });

      export const makeBlock = function (items) {

          if (!items) return false;
          return new Block(items);
      };

      constructors.Block = Block;