Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build() Remove header.js, remove fabric global object, use exports from TS to build the lib #8549

Merged
merged 73 commits into from
Jan 3, 2023

Conversation

asturur
Copy link
Member

@asturur asturur commented Dec 30, 2022

Motivation

Try to package a build with proper import export withour relying on the fabric global object

Description

Slowly trying to get this to work, i hoped it was straight forward but it didn't work out of the box

Changes

Main changes

  • removed header and fabric global references from the source code.
  • In order to have document, window, isLikelyNode working a stopgap object returned from getEnv() has been created
  • removed index.js in favor of a standard import structure ( for now no exports )

Other changes

  • converted stateful mixin to have this working
  • removed setupState from the stateful mixin
  • util addListener and removeListener are gone

In Action

tsconfig.json Outdated
@@ -25,7 +25,7 @@

/* Modules */
"module": "es2022" /* Specify what module code is generated. */,
// "rootDir": "./", /* Specify the root folder within your source files. */
"rootDir": "./", /* Specify the root folder within your source files. */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the fixing change, could be that it would have worked with the old dependencies anyway

@github-actions
Copy link
Contributor

github-actions bot commented Dec 30, 2022

Build Stats

file / KB (diff) bundled minified
fabric 932.031 (-16.332) 300.908 (-4.655)

@asturur
Copy link
Member Author

asturur commented Dec 30, 2022

fabric 5 build output

{
  fabric: {
    version: '5.1.0',
    document: Document,
    jsdomImplForWrapper,
    nodeCanvas,
    window,
    isTouchSupported: false,
    isLikelyNode: true,
    SHARED_ATTRIBUTES: [
      'display',         'transform',
      'fill',            'fill-opacity',
      'fill-rule',       'opacity',
      'stroke',          'stroke-dasharray',
      'stroke-linecap',  'stroke-dashoffset',
      'stroke-linejoin', 'stroke-miterlimit',
      'stroke-opacity',  'stroke-width',
      'id',              'paint-order',
      'vector-effect',   'instantiated_by_use',
      'clip-path'
    ],
    DPI: 96,
    reNum: '(?:[-+]?(?:\\d+|\\d*\\.\\d+)(?:[eE][-+]?\\d+)?)',
    commaWsp: '(?:\\s+,?\\s*|,\\s*)',
    rePathCommand: /([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:[eE][-+]?\d+)?)/gi,
    reNonWord: /[ \n\.,;!\?\-]/,
    fontPaths: {},
    iMatrix: [ 1, 0, 0, 1, 0, 0 ],
    svgNS: 'http://www.w3.org/2000/svg',
    perfLimitSizeTotal: 2097152,
    maxCacheSideLimit: 4096,
    minCacheSideLimit: 256,
    charWidthsCache: {},
    textureSize: 2048,
    disableStyleCopyPaste: false,
    enableGLFiltering: true,
    devicePixelRatio: 1,
    browserShadowBlurConstant: 1,
    arcToSegmentsCache: {},
    boundsOfCurveCache: {},
    cachesBoundsOfCurve: true,
    forceGLPutImageData: false,
    initFilterBackend: [Function (anonymous)],
    Observable: {
      fire: [Function: fire],
      on: [Function: on],
      once: [Function: once],
      off: [Function: off]
    },
    Collection: {
      _objects: [],
      add: [Function: add],
      insertAt: [Function: insertAt],
      remove: [Function: remove],
      forEachObject: [Function: forEachObject],
      getObjects: [Function: getObjects],
      item: [Function: item],
      isEmpty: [Function: isEmpty],
      size: [Function: size],
      contains: [Function: contains],
      complexity: [Function: complexity]
    },
    CommonMethods: {
      _setOptions: [Function: _setOptions],
      _initGradient: [Function: _initGradient],
      _initPattern: [Function: _initPattern],
      _setObject: [Function: _setObject],
      set: [Function: set],
      _set: [Function: _set],
      toggle: [Function: toggle],
      get: [Function: get]
    },
    util: {
      cos: [Function: cos],
      sin: [Function: sin],
      removeFromArray: [Function: removeFromArray],
      getRandomInt: [Function: getRandomInt],
      degreesToRadians: [Function: degreesToRadians],
      radiansToDegrees: [Function: radiansToDegrees],
      rotatePoint: [Function: rotatePoint],
      rotateVector: [Function: rotateVector],
      createVector: [Function: createVector],
      calcAngleBetweenVectors: [Function: calcAngleBetweenVectors],
      getHatVector: [Function: getHatVector],
      getBisector: [Function: getBisector],
      projectStrokeOnPoints: [Function: projectStrokeOnPoints],
      transformPoint: [Function: transformPoint],
      makeBoundingBoxFromPoints: [Function: makeBoundingBoxFromPoints],
      invertTransform: [Function: invertTransform],
      toFixed: [Function: toFixed],
      parseUnit: [Function: parseUnit],
      falseFunction: [Function: falseFunction],
      getKlass: [Function: getKlass],
      getSvgAttributes: [Function: getSvgAttributes],
      resolveNamespace: [Function: resolveNamespace],
      loadImage: [Function: loadImage],
      loadImageInDom: [Function: loadImageInDom],
      enlivenObjects: [Function: enlivenObjects],
      enlivenObjectEnlivables: [Function: enlivenObjectEnlivables],
      enlivenPatterns: [Function: enlivenPatterns],
      groupSVGElements: [Function: groupSVGElements],
      populateWithProperties: [Function: populateWithProperties],
      createCanvasElement: [Function: createCanvasElement],
      copyCanvasElement: [Function: copyCanvasElement],
      toDataURL: [Function: toDataURL],
      createImage: [Function: createImage],
      multiplyTransformMatrices: [Function: multiplyTransformMatrices],
      qrDecompose: [Function: qrDecompose],
      calcRotateMatrix: [Function: calcRotateMatrix],
      calcDimensionsMatrix: [Function: calcDimensionsMatrix],
      composeMatrix: [Function: composeMatrix],
      resetObjectTransform: [Function: resetObjectTransform],
      saveObjectTransform: [Function: saveObjectTransform],
      isTransparent: [Function: isTransparent],
      parsePreserveAspectRatioAttribute: [Function: parsePreserveAspectRatioAttribute],
      clearFabricFontCache: [Function: clearFabricFontCache],
      limitDimsByArea: [Function: limitDimsByArea],
      capValue: [Function: capValue],
      findScaleToFit: [Function: findScaleToFit],
      findScaleToCover: [Function: findScaleToCover],
      matrixToSVG: [Function: matrixToSVG],
      removeTransformFromObject: [Function: removeTransformFromObject],
      addTransformToObject: [Function: addTransformToObject],
      applyTransformToObject: [Function: applyTransformToObject],
      sizeAfterTransform: [Function: sizeAfterTransform],
      mergeClipPaths: [Function: mergeClipPaths],
      joinPath: [Function (anonymous)],
      parsePath: [Function: parsePath],
      makePathSimpler: [Function: makePathSimpler],
      getSmoothPathFromPoints: [Function: getSmoothPathFromPoints],
      getPathSegmentsInfo: [Function: getPathSegmentsInfo],
      getBoundsOfCurve: [Function: getBoundsOfCurve],
      getPointOnPath: [Function: getPointOnPath],
      transformPath: [Function: transformPath],
      array: [Object],
      object: [Object],
      fire: [Function: fire],
      on: [Function: on],
      once: [Function: once],
      off: [Function: off],
      string: [Object],
      createClass: [Function: createClass],
      addListener: [Function (anonymous)],
      removeListener: [Function (anonymous)],
      getPointer: [Function (anonymous)],
      isTouchEvent: [Function (anonymous)],
      setStyle: [Function: setStyle],
      makeElementUnselectable: [Function: makeElementUnselectable],
      makeElementSelectable: [Function: makeElementSelectable],
      setImageSmoothing: [Function: setImageSmoothing],
      getById: [Function: getById],
      toArray: [Function: toArray],
      addClass: [Function: addClass],
      makeElement: [Function: makeElement],
      wrapElement: [Function: wrapElement],
      getScrollLeftTop: [Function: getScrollLeftTop],
      getElementOffset: [Function: getElementOffset],
      getNodeCanvas: [Function: getNodeCanvas],
      cleanUpJsdomNode: [Function: cleanUpJsdomNode],
      request: [Function: request],
      animate: [Function: animate],
      requestAnimFrame: [Function: requestAnimFrame],
      cancelAnimFrame: [Function: cancelAnimFrame],
      animateColor: [Function: animateColor],
      ease: [Object]
    },
    log: [Function: log],
    warn: [Function: warn],
    runningAnimations: [
      cancelAll: [Function: cancelAll],
      cancelByCanvas: [Function: cancelByCanvas],
      cancelByTarget: [Function: cancelByTarget],
      findAnimationIndex: [Function: findAnimationIndex],
      findAnimation: [Function: findAnimation],
      findAnimationsByTarget: [Function: findAnimationsByTarget]
    ],
    svgValidTagNamesRegEx: /^(path|circle|polygon|polyline|ellipse|rect|line|image|text)\b/i,
    svgViewBoxElementsRegEx: /^(symbol|image|marker|pattern|view|svg)\b/i,
    svgInvalidAncestorsRegEx: /^(pattern|defs|symbol|metadata|clipPath|mask|desc)\b/i,
    svgValidParentsRegEx: /^(symbol|g|a|svg|clipPath|defs)\b/i,
    cssRules: {},
    gradientDefs: {},
    clipPaths: {},
    parseTransformAttribute: [Function (anonymous)],
    parseSVGDocument: [Function (anonymous)],
    parseFontDeclaration: [Function: parseFontDeclaration],
    getGradientDefs: [Function: getGradientDefs],
    parseAttributes: [Function: parseAttributes],
    parseElements: [Function: parseElements],
    parseStyleAttribute: [Function: parseStyleAttribute],
    parsePointsAttribute: [Function: parsePointsAttribute],
    getCSSRules: [Function: getCSSRules],
    loadSVGFromURL: [Function: loadSVGFromURL],
    loadSVGFromString: [Function: loadSVGFromString],
    ElementsParser: [Function (anonymous)],
    Point: [Function: Point],
    Intersection: [Function: Intersection] {
      intersectLineLine: [Function (anonymous)],
      intersectLinePolygon: [Function (anonymous)],
      intersectPolygonPolygon: [Function (anonymous)],
      intersectPolygonRectangle: [Function (anonymous)]
    },
    Color: [Function: Color] {
      reRGBa: /^rgba?\(\s*(\d{1,3}(?:\.\d+)?\%?)\s*,\s*(\d{1,3}(?:\.\d+)?\%?)\s*,\s*(\d{1,3}(?:\.\d+)?\%?)\s*(?:\s*,\s*((?:\d*\.?\d+)?)\s*)?\)$/i,
      reHSLa: /^hsla?\(\s*(\d{1,3})\s*,\s*(\d{1,3}\%)\s*,\s*(\d{1,3}\%)\s*(?:\s*,\s*(\d+(?:\.\d+)?)\s*)?\)$/i,
      reHex: /^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i,
      colorNameMap: [Object],
      fromRgb: [Function (anonymous)],
      sourceFromRgb: [Function (anonymous)],
      fromRgba: [Function (anonymous)],
      fromHsl: [Function (anonymous)],
      sourceFromHsl: [Function (anonymous)],
      fromHsla: [Function (anonymous)],
      fromHex: [Function (anonymous)],
      sourceFromHex: [Function (anonymous)],
      fromSource: [Function (anonymous)]
    },
    controlsUtils: {
      scaleCursorStyleHandler: [Function: scaleCursorStyleHandler],
      skewCursorStyleHandler: [Function: skewCursorStyleHandler],
      scaleSkewCursorStyleHandler: [Function: scaleSkewCursorStyleHandler],
      rotationWithSnapping: [Function (anonymous)],
      scalingEqually: [Function (anonymous)],
      scalingX: [Function (anonymous)],
      scalingY: [Function (anonymous)],
      scalingYOrSkewingX: [Function: scalingYOrSkewingX],
      scalingXOrSkewingY: [Function: scalingXOrSkewingY],
      changeWidth: [Function (anonymous)],
      skewHandlerX: [Function: skewHandlerX],
      skewHandlerY: [Function: skewHandlerY],
      dragHandler: [Function: dragHandler],
      scaleOrSkewActionName: [Function: scaleOrSkewActionName],
      rotationStyleHandler: [Function: rotationStyleHandler],
      fireEvent: [Function: fireEvent],
      wrapWithFixedAnchor: [Function: wrapWithFixedAnchor],
      wrapWithFireEvent: [Function: wrapWithFireEvent],
      getLocalPoint: [Function: getLocalPoint],
      renderCircleControl: [Function: renderCircleControl],
      renderSquareControl: [Function: renderSquareControl]
    },
    Control: [Function: Control],
    Gradient: [Function: klass] {
      superclass: null,
      subclasses: [],
      fromElement: [Function: fromElement]
    },
    Pattern: [Function: klass] { superclass: null, subclasses: [] },
    Shadow: [Function: klass] {
      superclass: null,
      subclasses: [],
      reOffsetsAndBlur: /(?:\s|^)(-?\d+(?:\.\d*)?(?:px)?(?:\s?|$))?(-?\d+(?:\.\d*)?(?:px)?(?:\s?|$))?(\d+(?:\.\d*)?(?:px)?)?(?:\s?|$)(?:$|\s)/
    },
    StaticCanvas: [Function: klass] {
      superclass: null,
      subclasses: [Array],
      EMPTY_JSON: '{"objects": [], "background": "white"}',
      supports: [Function: supports]
    },
    BaseBrush: [Function: klass] { superclass: null, subclasses: [Array] },
    PencilBrush: [Function: klass] { superclass: [Function], subclasses: [Array] },
    CircleBrush: [Function: klass] { superclass: [Function], subclasses: [] },
    SprayBrush: [Function: klass] { superclass: [Function], subclasses: [] },
    PatternBrush: [Function: klass] { superclass: [Function], subclasses: [] },
    Canvas: [Function: klass] {
      superclass: null,
      subclasses: [Array],
      EMPTY_JSON: '{"objects": [], "background": "white"}',
      supports: [Function: supports]
    },
    Object: [Function: klass] {
      superclass: null,
      subclasses: [Array],
      NUM_FRACTION_DIGITS: 2,
      ENLIVEN_PROPS: [Array],
      _fromObject: [Function (anonymous)],
      __uid: 0
    },
    Line: [Function: klass] {
      superclass: [Function],
      subclasses: [],
      ATTRIBUTE_NAMES: [Array],
      fromElement: [Function (anonymous)],
      fromObject: [Function (anonymous)]
    },
    Circle: [Function: klass] {
      superclass: [Function],
      subclasses: [],
      ATTRIBUTE_NAMES: [Array],
      fromElement: [Function (anonymous)],
      fromObject: [Function (anonymous)]
    },
    Triangle: [Function: klass] {
      superclass: [Function],
      subclasses: [],
      fromObject: [Function (anonymous)]
    },
    Ellipse: [Function: klass] {
      superclass: [Function],
      subclasses: [],
      ATTRIBUTE_NAMES: [Array],
      fromElement: [Function (anonymous)],
      fromObject: [Function (anonymous)]
    },
    Rect: [Function: klass] {
      superclass: [Function],
      subclasses: [],
      ATTRIBUTE_NAMES: [Array],
      fromElement: [Function (anonymous)],
      fromObject: [Function (anonymous)]
    },
    Polyline: [Function: klass] {
      superclass: [Function],
      subclasses: [Array],
      ATTRIBUTE_NAMES: [Array],
      fromElementGenerator: [Function (anonymous)],
      fromElement: [Function (anonymous)],
      fromObject: [Function (anonymous)]
    },
    Polygon: [Function: klass] {
      superclass: [Function],
      subclasses: [],
      ATTRIBUTE_NAMES: [Array],
      fromElement: [Function (anonymous)],
      fromObject: [Function (anonymous)]
    },
    Path: [Function: klass] {
      superclass: [Function],
      subclasses: [],
      fromObject: [Function (anonymous)],
      ATTRIBUTE_NAMES: [Array],
      fromElement: [Function (anonymous)]
    },
    Group: [Function: klass] {
      superclass: [Function],
      subclasses: [Array],
      fromObject: [Function (anonymous)]
    },
    ActiveSelection: [Function: klass] {
      superclass: [Function],
      subclasses: [],
      fromObject: [Function (anonymous)]
    },
    Image: [Function: klass] {
      superclass: [Function],
      subclasses: [],
      CSS_CANVAS: 'canvas-img',
      fromObject: [Function (anonymous)],
      fromURL: [Function (anonymous)],
      ATTRIBUTE_NAMES: [Array],
      fromElement: [Function (anonymous)],
      filters: [Object]
    },
    isWebglSupported: [Function (anonymous)],
    WebglFilterBackend: [Function: WebglFilterBackend],
    Canvas2dFilterBackend: [Function: Canvas2dFilterBackend],
    Text: [Function: klass] {
      superclass: [Function],
      subclasses: [Array],
      ATTRIBUTE_NAMES: [Array],
      DEFAULT_SVG_FONT_SIZE: 16,
      fromElement: [Function (anonymous)],
      fromObject: [Function (anonymous)],
      genericFonts: [Array]
    },
    IText: [Function: klass] {
      superclass: [Function],
      subclasses: [Array],
      fromObject: [Function (anonymous)]
    },
    Textbox: [Function: klass] {
      superclass: [Function],
      subclasses: [],
      fromObject: [Function (anonymous)]
    }
  }
}

@asturur
Copy link
Member Author

asturur commented Dec 31, 2022

type generation does not work, this ecosystem is shit.

@ShaMan123
Copy link
Contributor

ShaMan123 commented Dec 31, 2022

Why do you dislike the index files?
I don't get it.
It makes sense to have an index file for controls, brushes etc.
imports are broken because of it

@ShaMan123
Copy link
Contributor

Seems to work now

@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2023

Coverage after merging bundle into master will be

83.21%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
index.js35%12.50%0%54.55%430, 432, 432, 432, 432, 432, 434–435, 437, 437, 437–438
src
   cache.ts96.97%90%100%100%56
   config.ts77.27%66.67%66.67%84.62%130, 138–140, 151–153
   constants.ts100%100%100%100%
   env.ts72.73%53.33%100%79.17%22, 22–23, 23, 23, 25, 25, 27, 29, 31–32, 62
   intersection.class.ts100%100%100%100%
   pattern.class.ts92.19%85.71%100%96.30%118, 124, 135, 144, 96
   point.class.ts100%100%100%100%
   shadow.class.ts98.48%96%100%100%156
src/brushes
   base_brush.class.ts100%100%100%100%
   circle_brush.class.ts0%0%0%0%100, 102–104, 113, 113, 113, 115, 117, 119–121, 123–126, 134, 141, 143, 23, 28–29, 37–41, 45–49, 56–59, 67–71, 73, 81, 81, 81, 81, 81–82, 84, 84, 84–87, 89, 97–98
   pattern_brush.class.ts97.06%87.50%100%100%21
   pencil_brush.class.ts91.86%85.42%100%93.58%122–123, 152, 152–154, 276, 280, 285–286, 68–69, 84–85
   spray_brush.class.ts0%0%0%0%100–101, 103–104, 112, 112, 112, 112, 112–113, 115–116, 123–124, 126, 128–132, 141, 145–146, 146, 154, 154, 154–157, 159–162, 166–167, 169, 171–174, 177, 184–185, 187, 189–190, 192, 199–200, 202–203, 206, 206, 213, 213, 217, 22–23, 25–27, 27, 27–29, 33, 42, 49, 56, 63, 70, 77, 89–91, 99
src/canvas
   canvas.class.ts92.52%88.15%94.12%95.45%1151, 1151–1152, 1155, 1175, 1175, 1237, 1273–1274, 1293–1294, 1302–1303, 1324, 1332, 1445–1446, 1448–1449, 1469–1470, 1633–1634, 1638, 510, 577–578, 583, 593, 722–723, 725–726, 726, 726, 772–773, 834–835, 838, 840, 885–887, 917, 922–923, 952–953
   canvas_events.ts78.08%75%82.81%79.48%1003–1004, 1004, 1004–1006, 1008–1009, 1009, 1009, 1011, 1019, 1019, 1019–1021, 1021, 1021, 1027–1028, 1036–1037, 1037, 1037–1038, 1043, 1045, 1075–1077, 1080–1081, 1085–1086, 1184, 1204–1206, 1209–1210, 1282, 1369, 1402, 145, 1496–1497, 1503, 1507–1508, 1524, 1546, 1593, 1598, 1637, 170, 318–319, 319, 319–320, 320, 323–327, 332, 334, 346–348, 351, 368, 368, 368–369, 369, 369–370, 378, 383–384, 384, 384–385, 387, 396, 402–403, 403, 403, 439, 443, 443, 443, 443, 443–444, 446, 521, 523, 523, 523–525, 545, 547, 547, 547–548, 548, 548, 551, 551, 551–552, 555, 564–565, 567–568, 570, 570–571, 573–574, 586–587, 587, 587–588, 590–594, 600, 607, 647, 647, 647, 649, 651–655, 661, 667, 667, 667–668, 670, 673, 678, 691, 718, 774–775, 775, 775–776, 778, 781–782, 782, 782–783, 785–786, 789, 789–791, 794–795, 805, 887, 901, 908, 929, 961, 982–983, 989
   static_canvas.class.ts94.56%88.89%97.92%97.12%1128–1129, 1129, 1129–1130, 1250, 1260, 1314–1315, 1318, 1353–1354, 1432, 1441, 1446, 1495–1496, 1724, 1724–1725, 1775, 1778, 1781, 1781, 1781, 1784, 1787, 1787, 1787, 309, 345, 358, 414–415, 417–418, 427, 431–432, 435–436, 888
src/color
   color.class.ts92.16%86.49%100%94.29%330–331, 335–336, 339–340, 58, 88–89, 89, 91, 91, 91–92, 94–95
   color_map.ts100%100%100%100%
   constants.ts100%100%100%100%
   util.ts100%100%100%100%
src/controls
   changeWidth.ts100%100%100%100%
   control.class.ts93.90%88.89%90.91%97.73%235, 319, 319, 354
   controls.render.ts81.63%78%100%84.78%106, 111, 121, 121, 45, 50, 61, 61, 65–72, 81–82
   default_controls.ts86.67%66.67%100%100%122, 129
   drag.ts100%100%100%100%
   rotate.ts20%12.50%50%22.22%45, 51, 51, 51–52, 55–57, 59, 59, 59, 59, 59–61, 61, 61–63, 65, 65, 65–67, 67, 67–68, 73, 73, 73–74, 76, 78, 80–81
   scale.ts93.41%92.68%100%93.59%129–130, 132–134, 148–149, 181–183, 42
   scaleSkew.ts78.79%64.29%100%85.71%27, 29, 29, 29, 31, 33, 35
   skew.ts91.03%79.31%100%97.67%130–131, 162–163, 170, 176, 178
   util.ts100%100%100%100%
   wrapWithFireEvent.ts100%100%100%100%
   wrapWithFixedAnchor.ts100%100%100%100%
src/filters
   2d_backend.class.ts92%83.33%100%93.75%35–36
   FilterBackend.ts88.89%88.89%100%85.71%15–16
   WebGLProbe.ts40.54%40%60%36.36%28–30, 30, 30–31, 33–35, 43, 46–48, 48, 48–51, 53, 58
   base_filter.class.ts20.83%20.83%33.33%18.18%102–104, 104, 104–105, 112–115, 115, 115–116, 122, 122, 122–125, 143, 173–178, 182–183, 183,

@asturur
Copy link
Member Author

asturur commented Jan 2, 2023

Ok i still need to make a real compare between this export and old export and see what got lost, but this is ready to go.
All changes that were part of the previous tenative of using exports or rationalizing things have been removed.
There is only header and fabric. removal and the stopgap getEnv.

getEnv or config are somehow related.
We can argue document and window are part of the env, but so is the retina scaling value.
FilterBackend is probably part of the env or of the config, we could make cases that make both seem appropriate.

@ShaMan123 give it another check.

I didn't remove any utils, not even the internal one.
With the current test framework removing a util from the export means not testing it.

@asturur
Copy link
Member Author

asturur commented Jan 2, 2023

also 16k of unminified code disapparead means i forgot something.

400 lines of code are missing. and 4k bytes.

@asturur asturur requested a review from ShaMan123 January 3, 2023 01:16
@asturur asturur changed the title build() WIP experimenting with proper import/export - nothing works right now build() Remove header.js, remove fabric global object, use exports from TS to build the lib Jan 3, 2023
@ShaMan123
Copy link
Contributor

We can argue document and window are part of the env, but so is the retina scaling value.

devicePixelRatio is definitely part of env. I put it in config cause there was no better option at the time. But it is not configurable, it is a device preset, so it belongs to env.

FilterBackend should be configurable. But maybe it should be standalone and have a setter of its own. Not sure.

Copy link
Contributor

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO env should be a class with an exported instance, same as config for the following reasons:

  • test stubbing/mocking is easy (no need for setEnvForTests, an object is better to export in this case than multiple exports)
  • setting up custom env can done easily by the dev (subclassing) if we expose some setters
  • internal state (is initialized etc.). We will probably need that when tackling SSR and node env.
  • code styling

Shouldn't the index file be .ts? And shouldn't it reside under src?

All in all looks fine

Comment on lines +430 to +439
if (typeof exports !== 'undefined') {
exports.fabric = fabric;
} else if (typeof define === 'function' && define.amd) {
/* _AMD_START_ */
define([], function () {
return fabric;
});
} else if (typeof window !== 'undefined') {
window.fabric = fabric;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about this?
next PR?
this is handled by the umd output in rollup

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to fix exports.
Then this will go away automagically i hope.
Next PR or next 2, or next 3, i m not sure how hard it is.
That issue we had with prototype breaking and i m pointing the finger to different transpiling could be a pandora box of issues

});
}

setupEnv();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.
So we are talking about drp right?
If we move it to env will that be enough to do a lazy init?

src/filters/FilterBackend.ts Outdated Show resolved Hide resolved
src/mixins/stateful.mixin.ts Outdated Show resolved Hide resolved
src/shapes/Object/StackedObject.ts Outdated Show resolved Hide resolved
@ShaMan123
Copy link
Contributor

ShaMan123 commented Jan 3, 2023

also 16k of unminified code disapparead means i forgot something.

400 lines of code are missing. and 4k bytes.

All the index files

index.js could be slimmer if we use the removed index files which would have levelled the count

Co-authored-by: Shachar <34343793+ShaMan123@users.noreply.github.com>
@asturur
Copy link
Member Author

asturur commented Jan 3, 2023

also 16k of unminified code disapparead means i forgot something.
400 lines of code are missing. and 4k bytes.

All the index files

index.js could be slimmer if we use the removed index files which would have levelled the count

The removed index files didn't get in the final build ever, unless you would use them as objects ( for example easing did, but wasn't 400 lines ).
Something else is missing and will pop out as something untested.
Canvas.fxRemove and fxStraighten is one piece, but is not all.

@asturur asturur merged commit 284b3ab into master Jan 3, 2023
frankrousseau pushed a commit to cgwire/fabric.js that referenced this pull request Jan 6, 2023
@ShaMan123 ShaMan123 deleted the bundle branch February 5, 2023 05:19
ShaMan123 pushed a commit that referenced this pull request Mar 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants