@ngstarter-ui/components 22.3.1 → 22.3.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.
@@ -3,7 +3,7 @@
3
3
  "generatedBy": "scripts/generate-ai-metadata.mjs",
4
4
  "package": "@ngstarter-ui/components",
5
5
  "description": "AI-readable registry for NgStarter UI Angular secondary entry points.",
6
- "componentCount": 126,
6
+ "componentCount": 127,
7
7
  "conventions": {
8
8
  "importPattern": "@ngstarter-ui/components/<component>",
9
9
  "selectorPrefix": "ngs",
@@ -2018,8 +2018,12 @@
2018
2018
  "colorChange"
2019
2019
  ],
2020
2020
  "cssTokens": [
2021
+ "--ngs-brand-colors-color-shadow",
2021
2022
  "--ngs-brand-colors-color-size",
2022
2023
  "--ngs-brand-colors-gap",
2024
+ "--ngs-brand-colors-selected-dot-size",
2025
+ "--ngs-brand-colors-selected-outline",
2026
+ "--ngs-brand-colors-selected-outline-offset",
2023
2027
  "--ngs-shadow-sm"
2024
2028
  ],
2025
2029
  "example": null
@@ -10632,12 +10636,15 @@
10632
10636
  "ngs-tiles"
10633
10637
  ],
10634
10638
  "exportedSymbols": [
10639
+ "exchangeTileGroup",
10640
+ "findTileGroup",
10635
10641
  "ReorderFunction",
10636
10642
  "Tile",
10637
10643
  "TileHandleDirective",
10638
10644
  "Tiles",
10639
10645
  "TILES_REORDER",
10640
10646
  "TileService",
10647
+ "TileSlot",
10641
10648
  "tilesShift",
10642
10649
  "tilesSwap"
10643
10650
  ],
@@ -11673,6 +11680,159 @@
11673
11680
  "outputs": [],
11674
11681
  "cssTokens": [],
11675
11682
  "example": null
11683
+ },
11684
+ {
11685
+ "name": "whiteboard",
11686
+ "title": "Whiteboard",
11687
+ "overviewName": "Whiteboard",
11688
+ "category": "components",
11689
+ "package": "@ngstarter-ui/components",
11690
+ "importPath": "@ngstarter-ui/components/whiteboard",
11691
+ "publicApi": "projects/components/whiteboard/public-api.ts",
11692
+ "sourceRoot": "projects/components/whiteboard/src",
11693
+ "docsPath": "/components/whiteboard",
11694
+ "docsOverviewSource": "projects/docs/src/app/components/whiteboard/overview/overview.html",
11695
+ "purpose": "Draw freehand sketches, shapes, diagrams, text and notes on a Konva.js canvas.",
11696
+ "useWhen": "Use ngs-whiteboard for editable idea boards, diagramming and sketches with selection, move/resize/rotate, stroke/fill controls, undo/redo, pan/zoom and PNG/JSON export. Bind value to a version 1 WhiteboardDocument, persist valueChange in application code, and use readonly for viewing. Use SignaturePad for signature fields, ImageDesigner for image composition and ContentEditor for rich document editing. Realtime collaboration and persistence belong to the consuming application.",
11697
+ "exampleTopics": [
11698
+ "Drawing and diagrams",
11699
+ "Keyboard shortcuts",
11700
+ "Integration",
11701
+ "Basic whiteboard"
11702
+ ],
11703
+ "minimalExample": "<ngs-whiteboard class=\"group-[.playground-expanded]/playground:h-full! group-[.playground-expanded]/playground:min-h-0!\"\n [(value)]=\"board\" [title]=\"'Idea board'\"/>",
11704
+ "exampleFiles": [
11705
+ {
11706
+ "name": "basic-whiteboard-example",
11707
+ "title": "Basic whiteboard",
11708
+ "file": "projects/docs/src/app/components/whiteboard/_examples/basic-whiteboard-example/basic-whiteboard-example.html",
11709
+ "source": "<ngs-whiteboard class=\"group-[.playground-expanded]/playground:h-full! group-[.playground-expanded]/playground:min-h-0!\"\n [(value)]=\"board\" [title]=\"'Idea board'\"/>"
11710
+ }
11711
+ ],
11712
+ "previewAsset": null,
11713
+ "selectors": [
11714
+ "ngs-whiteboard"
11715
+ ],
11716
+ "exportedSymbols": [
11717
+ "bindingKey",
11718
+ "connectorBendPoint",
11719
+ "ConnectorEnd",
11720
+ "connectorEndPoint",
11721
+ "connectorEnds",
11722
+ "connectorPath",
11723
+ "findBinding",
11724
+ "hasWhiteboardText",
11725
+ "isConnector",
11726
+ "isConnectorObscured",
11727
+ "parseWhiteboardDocument",
11728
+ "resolveBindings",
11729
+ "resolveConnector",
11730
+ "setConnectorBend",
11731
+ "setConnectorEnds",
11732
+ "Whiteboard",
11733
+ "WHITEBOARD_LABELS",
11734
+ "WhiteboardBinding",
11735
+ "WhiteboardDocument",
11736
+ "WhiteboardElement",
11737
+ "WhiteboardElementType",
11738
+ "WhiteboardEngine",
11739
+ "WhiteboardExportOptions",
11740
+ "whiteboardFontFamily",
11741
+ "WhiteboardHistory",
11742
+ "WhiteboardLineStyle",
11743
+ "WhiteboardLocale",
11744
+ "WhiteboardStyle",
11745
+ "WhiteboardTextRequest",
11746
+ "WhiteboardTool",
11747
+ "WhiteboardTypography",
11748
+ "WhiteboardViewport",
11749
+ "zoomWhiteboardAt"
11750
+ ],
11751
+ "inputs": [
11752
+ "colors",
11753
+ "drawingStyle",
11754
+ "locale",
11755
+ "pressureSensitive",
11756
+ "readonly",
11757
+ "showGrid",
11758
+ "showProperties",
11759
+ "showToolbar",
11760
+ "subtitle",
11761
+ "title",
11762
+ "tool",
11763
+ "toolLocked",
11764
+ "value"
11765
+ ],
11766
+ "outputs": [
11767
+ "exported",
11768
+ "importError",
11769
+ "selectionChange",
11770
+ "viewportChange"
11771
+ ],
11772
+ "cssTokens": [
11773
+ "--ngs-brand-colors-color-shadow",
11774
+ "--ngs-brand-colors-color-size",
11775
+ "--ngs-brand-colors-gap",
11776
+ "--ngs-brand-colors-selected-dot-size",
11777
+ "--ngs-brand-colors-selected-outline",
11778
+ "--ngs-brand-colors-selected-outline-offset",
11779
+ "--ngs-button-bg",
11780
+ "--ngs-button-color",
11781
+ "--ngs-button-content-gap",
11782
+ "--ngs-button-font-size",
11783
+ "--ngs-button-height",
11784
+ "--ngs-button-outlined-border",
11785
+ "--ngs-button-padding",
11786
+ "--ngs-button-radius",
11787
+ "--ngs-button-toggle-button-border-radius",
11788
+ "--ngs-button-toggle-button-height",
11789
+ "--ngs-button-toggle-checked-bg-color",
11790
+ "--ngs-button-toggle-checked-text-color",
11791
+ "--ngs-button-toggle-group-bg",
11792
+ "--ngs-button-toggle-group-border-width",
11793
+ "--ngs-button-toggle-group-gap",
11794
+ "--ngs-button-toggle-group-padding",
11795
+ "--ngs-card-bg",
11796
+ "--ngs-card-border-color",
11797
+ "--ngs-card-radius",
11798
+ "--ngs-card-shadow",
11799
+ "--ngs-color-border",
11800
+ "--ngs-color-on-surface",
11801
+ "--ngs-color-on-surface-variant",
11802
+ "--ngs-color-picker-thumbnail-bg",
11803
+ "--ngs-color-picker-thumbnail-size",
11804
+ "--ngs-color-primary",
11805
+ "--ngs-color-primary-container",
11806
+ "--ngs-color-surface",
11807
+ "--ngs-color-surface-container-highest",
11808
+ "--ngs-color-surface-container-low",
11809
+ "--ngs-font-family-base",
11810
+ "--ngs-font-size-sm",
11811
+ "--ngs-icon-size",
11812
+ "--ngs-radius-lg",
11813
+ "--ngs-segmented-bg",
11814
+ "--ngs-segmented-button-height",
11815
+ "--ngs-segmented-button-min-width",
11816
+ "--ngs-segmented-button-radius",
11817
+ "--ngs-segmented-button-selected-bg",
11818
+ "--ngs-segmented-button-selected-color",
11819
+ "--ngs-segmented-button-selected-shadow",
11820
+ "--ngs-segmented-gap",
11821
+ "--ngs-segmented-padding",
11822
+ "--ngs-segmented-radius",
11823
+ "--ngs-slider-thumb-size",
11824
+ "--ngs-slider-track-active-height",
11825
+ "--ngs-slider-track-color",
11826
+ "--ngs-slider-track-height",
11827
+ "--ngs-state-focus-ring",
11828
+ "--ngs-toolbar-gap",
11829
+ "--ngs-whiteboard-bg",
11830
+ "--ngs-whiteboard-grid-color",
11831
+ "--ngs-whiteboard-height",
11832
+ "--ngs-whiteboard-panel-bg",
11833
+ "--ngs-whiteboard-panel-shadow"
11834
+ ],
11835
+ "example": null
11676
11836
  }
11677
11837
  ]
11678
11838
  }
@@ -50,7 +50,7 @@ class ColorSwitcher {
50
50
  useExisting: forwardRef(() => ColorSwitcher),
51
51
  multi: true
52
52
  }
53
- ], exportAs: ["ngsColorSwitcher"], usesOnChanges: true, ngImport: i0, template: "@for (color of colors(); track color) {\n <button class=\"color\"\n type=\"button\"\n [style.--color]=\"color\"\n [class.is-selected]=\"_selectedColor === color\"\n (click)=\"selectColor(color)\">\n </button>\n}\n", styles: [":host{--ngs-brand-colors-color-size: calc(var(--spacing, .25rem) * 7);--ngs-brand-colors-gap: calc(var(--spacing, .25rem) * 3);display:inline-flex;flex-wrap:wrap;gap:var(--ngs-brand-colors-gap);line-height:0}:host .color{--color: transparent;width:var(--ngs-brand-colors-color-size);height:var(--ngs-brand-colors-color-size);border-radius:calc(infinity * 1px);transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s;position:relative;background:var(--color);line-height:0;flex:none;cursor:pointer;color:#fff;display:flex;align-items:center;justify-content:center;font-weight:700;box-shadow:#32325d26 0 2px 8px inset}:host .color:hover{scale:1.05}:host .color:active{scale:.95}:host .color.is-selected:before{content:\"\";position:absolute;border-radius:calc(infinity * 1px);background:#fff;width:calc(var(--spacing, .25rem) * 3);height:calc(var(--spacing, .25rem) * 3);top:50%;left:50%;transform:translate(-50%,-50%);z-index:1;box-shadow:var(--ngs-shadow-sm)}:host.is-disabled{pointer-events:none;opacity:60%}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"], changeDetection: i0.ChangeDetectionStrategy.Eager });
53
+ ], exportAs: ["ngsColorSwitcher"], usesOnChanges: true, ngImport: i0, template: "@for (color of colors(); track color) {\n <button class=\"color\"\n type=\"button\"\n [style.--color]=\"color\"\n [class.is-selected]=\"_selectedColor === color\"\n (click)=\"selectColor(color)\">\n </button>\n}\n", styles: [":host{--ngs-brand-colors-color-size: calc(var(--spacing, .25rem) * 7);--ngs-brand-colors-gap: calc(var(--spacing, .25rem) * 3);display:inline-flex;flex-wrap:wrap;gap:var(--ngs-brand-colors-gap);line-height:0}:host .color{--color: transparent;width:var(--ngs-brand-colors-color-size);height:var(--ngs-brand-colors-color-size);border-radius:calc(infinity * 1px);transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s;position:relative;background:var(--color);line-height:0;flex:none;cursor:pointer;color:#fff;display:flex;align-items:center;justify-content:center;font-weight:700;box-shadow:var(--ngs-brand-colors-color-shadow, rgba(50, 50, 93, .15) 0 2px 8px 0 inset)}:host .color:hover{scale:1.05}:host .color:active{scale:.95}:host .color.is-selected{outline:var(--ngs-brand-colors-selected-outline, none);outline-offset:var(--ngs-brand-colors-selected-outline-offset, 0)}:host .color.is-selected:before{content:\"\";position:absolute;border-radius:calc(infinity * 1px);background:#fff;width:var(--ngs-brand-colors-selected-dot-size, calc(var(--spacing, .25rem) * 3));height:var(--ngs-brand-colors-selected-dot-size, calc(var(--spacing, .25rem) * 3));top:50%;left:50%;transform:translate(-50%,-50%);z-index:1;box-shadow:var(--ngs-shadow-sm)}:host.is-disabled{pointer-events:none;opacity:60%}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"], changeDetection: i0.ChangeDetectionStrategy.Eager });
54
54
  }
55
55
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: ColorSwitcher, decorators: [{
56
56
  type: Component,
@@ -63,7 +63,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImpor
63
63
  ], changeDetection: ChangeDetectionStrategy.Eager, host: {
64
64
  'class': 'ngs-brand-colors',
65
65
  '[class.is-disabled]': 'disabled() || _disabled',
66
- }, template: "@for (color of colors(); track color) {\n <button class=\"color\"\n type=\"button\"\n [style.--color]=\"color\"\n [class.is-selected]=\"_selectedColor === color\"\n (click)=\"selectColor(color)\">\n </button>\n}\n", styles: [":host{--ngs-brand-colors-color-size: calc(var(--spacing, .25rem) * 7);--ngs-brand-colors-gap: calc(var(--spacing, .25rem) * 3);display:inline-flex;flex-wrap:wrap;gap:var(--ngs-brand-colors-gap);line-height:0}:host .color{--color: transparent;width:var(--ngs-brand-colors-color-size);height:var(--ngs-brand-colors-color-size);border-radius:calc(infinity * 1px);transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s;position:relative;background:var(--color);line-height:0;flex:none;cursor:pointer;color:#fff;display:flex;align-items:center;justify-content:center;font-weight:700;box-shadow:#32325d26 0 2px 8px inset}:host .color:hover{scale:1.05}:host .color:active{scale:.95}:host .color.is-selected:before{content:\"\";position:absolute;border-radius:calc(infinity * 1px);background:#fff;width:calc(var(--spacing, .25rem) * 3);height:calc(var(--spacing, .25rem) * 3);top:50%;left:50%;transform:translate(-50%,-50%);z-index:1;box-shadow:var(--ngs-shadow-sm)}:host.is-disabled{pointer-events:none;opacity:60%}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"] }]
66
+ }, template: "@for (color of colors(); track color) {\n <button class=\"color\"\n type=\"button\"\n [style.--color]=\"color\"\n [class.is-selected]=\"_selectedColor === color\"\n (click)=\"selectColor(color)\">\n </button>\n}\n", styles: [":host{--ngs-brand-colors-color-size: calc(var(--spacing, .25rem) * 7);--ngs-brand-colors-gap: calc(var(--spacing, .25rem) * 3);display:inline-flex;flex-wrap:wrap;gap:var(--ngs-brand-colors-gap);line-height:0}:host .color{--color: transparent;width:var(--ngs-brand-colors-color-size);height:var(--ngs-brand-colors-color-size);border-radius:calc(infinity * 1px);transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s;position:relative;background:var(--color);line-height:0;flex:none;cursor:pointer;color:#fff;display:flex;align-items:center;justify-content:center;font-weight:700;box-shadow:var(--ngs-brand-colors-color-shadow, rgba(50, 50, 93, .15) 0 2px 8px 0 inset)}:host .color:hover{scale:1.05}:host .color:active{scale:.95}:host .color.is-selected{outline:var(--ngs-brand-colors-selected-outline, none);outline-offset:var(--ngs-brand-colors-selected-outline-offset, 0)}:host .color.is-selected:before{content:\"\";position:absolute;border-radius:calc(infinity * 1px);background:#fff;width:var(--ngs-brand-colors-selected-dot-size, calc(var(--spacing, .25rem) * 3));height:var(--ngs-brand-colors-selected-dot-size, calc(var(--spacing, .25rem) * 3));top:50%;left:50%;transform:translate(-50%,-50%);z-index:1;box-shadow:var(--ngs-shadow-sm)}:host.is-disabled{pointer-events:none;opacity:60%}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"] }]
67
67
  }], propDecorators: { colors: [{ type: i0.Input, args: [{ isSignal: true, alias: "colors", required: false }] }], selectedColor: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectedColor", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], colorChange: [{ type: i0.Output, args: ["colorChange"] }] } });
68
68
 
69
69
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ngstarter-ui-components-color-switcher.mjs","sources":["../../../projects/components/color-switcher/src/color-switcher/color-switcher.ts","../../../projects/components/color-switcher/src/color-switcher/color-switcher.html","../../../projects/components/color-switcher/ngstarter-ui-components-color-switcher.ts"],"sourcesContent":["import {\n Component,\n OnChanges,\n SimpleChanges,\n input,\n output,\n forwardRef,\n inject,\n ChangeDetectorRef, booleanAttribute,\n ChangeDetectionStrategy\n} from '@angular/core';\nimport { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';\nimport { BooleanInput, coerceBooleanProperty } from '@angular/cdk/coercion';\n\nconst defaultColors = [\n '#35d1b3', '#08b0fe', '#8268f2', '#ae52d3', '#eb4ea3',\n '#fb811e', '#fac624', '#c2c2c2', '#4ed7ff'\n];\n\n@Component({\n selector: 'ngs-color-switcher',\n exportAs: 'ngsColorSwitcher',\n imports: [],\n providers: [\n {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => ColorSwitcher),\n multi: true\n }\n ],\n templateUrl: './color-switcher.html',\n styleUrl: './color-switcher.scss',\n changeDetection: ChangeDetectionStrategy.Eager,\n host: {\n 'class': 'ngs-brand-colors',\n '[class.is-disabled]': 'disabled() || _disabled',\n }\n})\nexport class ColorSwitcher implements ControlValueAccessor, OnChanges {\n private _cdr = inject(ChangeDetectorRef);\n protected _disabled = false;\n protected _selectedColor: string;\n\n colors = input<string[]>(defaultColors);\n selectedColor = input<string>();\n disabled = input(false, {\n transform: booleanAttribute\n });\n\n readonly colorChange = output<string>();\n\n _onChange: any = () => {};\n _onTouched: any = () => {};\n\n ngOnChanges(changes: SimpleChanges) {\n if (changes['selectedColor']) {\n this._selectedColor = changes['selectedColor'].currentValue;\n }\n }\n\n selectColor(color: string): void {\n this._selectedColor = color;\n this.colorChange.emit(color);\n this._onChange(color);\n this._onTouched(color);\n }\n\n writeValue(_selectedColor: any) {\n this._selectedColor = _selectedColor;\n this._cdr.detectChanges();\n }\n\n registerOnChange(fn: any): void {\n this._onChange = fn;\n }\n\n registerOnTouched(fn: any): void {\n this._onTouched = fn;\n }\n\n setDisabledState(isDisabled: BooleanInput): void {\n this._disabled = coerceBooleanProperty(isDisabled);\n }\n}\n","@for (color of colors(); track color) {\n <button class=\"color\"\n type=\"button\"\n [style.--color]=\"color\"\n [class.is-selected]=\"_selectedColor === color\"\n (click)=\"selectColor(color)\">\n </button>\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;AAcA,MAAM,aAAa,GAAG;AACpB,IAAA,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS;AACrD,IAAA,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE;CAClC;MAqBY,aAAa,CAAA;AAChB,IAAA,IAAI,GAAG,MAAM,CAAC,iBAAiB,CAAC;IAC9B,SAAS,GAAG,KAAK;AACjB,IAAA,cAAc;IAExB,MAAM,GAAG,KAAK,CAAW,aAAa;+EAAC;AACvC,IAAA,aAAa,GAAG,KAAK;iGAAU;IAC/B,QAAQ,GAAG,KAAK,CAAC,KAAK,gFACpB,SAAS,EAAE,gBAAgB,EAAA,CAC3B;IAEO,WAAW,GAAG,MAAM,EAAU;AAEvC,IAAA,SAAS,GAAQ,MAAK,EAAE,CAAC;AACzB,IAAA,UAAU,GAAQ,MAAK,EAAE,CAAC;AAE1B,IAAA,WAAW,CAAC,OAAsB,EAAA;AAChC,QAAA,IAAI,OAAO,CAAC,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,qBAAA,EAAA,QAAA,EAAA,6PAAA,EAAA,MAAA,EAAA,CAAA,omCAAA,CAAA,EAAA;;;AEpCH;;AAEG;;;;"}
1
+ {"version":3,"file":"ngstarter-ui-components-color-switcher.mjs","sources":["../../../projects/components/color-switcher/src/color-switcher/color-switcher.ts","../../../projects/components/color-switcher/src/color-switcher/color-switcher.html","../../../projects/components/color-switcher/ngstarter-ui-components-color-switcher.ts"],"sourcesContent":["import {\n Component,\n OnChanges,\n SimpleChanges,\n input,\n output,\n forwardRef,\n inject,\n ChangeDetectorRef, booleanAttribute,\n ChangeDetectionStrategy\n} from '@angular/core';\nimport { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';\nimport { BooleanInput, coerceBooleanProperty } from '@angular/cdk/coercion';\n\nconst defaultColors = [\n '#35d1b3', '#08b0fe', '#8268f2', '#ae52d3', '#eb4ea3',\n '#fb811e', '#fac624', '#c2c2c2', '#4ed7ff'\n];\n\n@Component({\n selector: 'ngs-color-switcher',\n exportAs: 'ngsColorSwitcher',\n imports: [],\n providers: [\n {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => ColorSwitcher),\n multi: true\n }\n ],\n templateUrl: './color-switcher.html',\n styleUrl: './color-switcher.scss',\n changeDetection: ChangeDetectionStrategy.Eager,\n host: {\n 'class': 'ngs-brand-colors',\n '[class.is-disabled]': 'disabled() || _disabled',\n }\n})\nexport class ColorSwitcher implements ControlValueAccessor, OnChanges {\n private _cdr = inject(ChangeDetectorRef);\n protected _disabled = false;\n protected _selectedColor: string;\n\n colors = input<string[]>(defaultColors);\n selectedColor = input<string>();\n disabled = input(false, {\n transform: booleanAttribute\n });\n\n readonly colorChange = output<string>();\n\n _onChange: any = () => {};\n _onTouched: any = () => {};\n\n ngOnChanges(changes: SimpleChanges) {\n if (changes['selectedColor']) {\n this._selectedColor = changes['selectedColor'].currentValue;\n }\n }\n\n selectColor(color: string): void {\n this._selectedColor = color;\n this.colorChange.emit(color);\n this._onChange(color);\n this._onTouched(color);\n }\n\n writeValue(_selectedColor: any) {\n this._selectedColor = _selectedColor;\n this._cdr.detectChanges();\n }\n\n registerOnChange(fn: any): void {\n this._onChange = fn;\n }\n\n registerOnTouched(fn: any): void {\n this._onTouched = fn;\n }\n\n setDisabledState(isDisabled: BooleanInput): void {\n this._disabled = coerceBooleanProperty(isDisabled);\n }\n}\n","@for (color of colors(); track color) {\n <button class=\"color\"\n type=\"button\"\n [style.--color]=\"color\"\n [class.is-selected]=\"_selectedColor === color\"\n (click)=\"selectColor(color)\">\n </button>\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;AAcA,MAAM,aAAa,GAAG;AACpB,IAAA,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS;AACrD,IAAA,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE;CAClC;MAqBY,aAAa,CAAA;AAChB,IAAA,IAAI,GAAG,MAAM,CAAC,iBAAiB,CAAC;IAC9B,SAAS,GAAG,KAAK;AACjB,IAAA,cAAc;IAExB,MAAM,GAAG,KAAK,CAAW,aAAa;+EAAC;AACvC,IAAA,aAAa,GAAG,KAAK;iGAAU;IAC/B,QAAQ,GAAG,KAAK,CAAC,KAAK,gFACpB,SAAS,EAAE,gBAAgB,EAAA,CAC3B;IAEO,WAAW,GAAG,MAAM,EAAU;AAEvC,IAAA,SAAS,GAAQ,MAAK,EAAE,CAAC;AACzB,IAAA,UAAU,GAAQ,MAAK,EAAE,CAAC;AAE1B,IAAA,WAAW,CAAC,OAAsB,EAAA;AAChC,QAAA,IAAI,OAAO,CAAC,eAAe,CAAC,EAAE;YAC5B,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC,YAAY;QAC7D;IACF;AAEA,IAAA,WAAW,CAAC,KAAa,EAAA;AACvB,QAAA,IAAI,CAAC,cAAc,GAAG,KAAK;AAC3B,QAAA,IAAI,CAAC,WAAW,CAAC,IA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,EAAA,KAAA,EAAA,iBAAA,EAAA,IAAA,EAAA,EAAA,EAAA,OAAA,EAAA,EAAA,WAAA,EAAA,aAAA,EAAA,EAAA,IAAA,EAAA,EAAA,UAAA,EAAA,EAAA,mBAAA,EAAA,yBAAA,EAAA,EAAA,cAAA,EAAA,kBAAA,EAAA,EAAA,SAAA,EAfb;AACT,YAAA;AACE,gBAAA,OAAO,EAAE,iBAAiB;AAC1B,gBAAA,WAAW,EAAE,UAAU,CAAC,MAAM,aAAa,CAAC;AAC5C,gBAAA,KAAK,EAAE;AACR;AACF,SAAA,EAAA,QAAA,EAAA,CAAA,kBAAA,CAAA,EAAA,aAAA,EAAA,IAAA,EAAA,QAAA,EAAA,EAAA,EAAA,QAAA,EC7BH,6PAQA,EAAA,MAAA,EAAA,CAAA,g4CAAA,CAAA,EAAA,eAAA,EAAA,EAAA,CAAA,uBAAA,CAAA,KAAA,EAAA,CAAA;;2FD8Ba,aAAa,EAAA,UAAA,EAAA,CAAA;kBAnBzB,SAAS;AACE,YAAA,IAAA,EAAA,CAAA,EAAA,QAAA,EAAA,oBAAoB,EAAA,QAAA,EACpB,kBAAkB,EAAA,OAAA,EACnB,EAAE,EAAA,SAAA,EACA;AACT,wBAAA;AACE,4BAAA,OAAO,EAAE,iBAAiB;AAC1B,4BAAA,WAAW,EAAE,UAAU,CAAC,mBAAmB,CAAC;AAC5C,4BAAA,KAAK,EAAE;AACR;qBACF,EAAA,eAAA,EAGgB,uBAAuB,CAAC,KAAK,EAAA,IAAA,EACxC;AACJ,wBAAA,OAAO,EAAE,kBAAkB;AAC3B,wBAAA,qBAAqB,EAAE,yBAAyB;AACjD,qBAAA,EAAA,QAAA,EAAA,6PAAA,EAAA,MAAA,EAAA,CAAA,g4CAAA,CAAA,EAAA;;;AEpCH;;AAEG;;;;"}
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, inject, signal, contentChildren, input, numberAttribute, output, effect, ChangeDetectionStrategy, Component, PLATFORM_ID, Injectable, viewChild, computed, Directive } from '@angular/core';
2
+ import { InjectionToken, inject, signal, contentChildren, input, numberAttribute, output, DestroyRef, effect, ChangeDetectionStrategy, Component, PLATFORM_ID, Injectable, viewChild, computed, Directive } from '@angular/core';
3
3
  import { BreakpointObserver } from '@angular/cdk/layout';
4
4
  import { injectElement, arrayShallowEquals, ResizeObserverService, MutationObserverService, zonefreeScheduler, px, typedFromEvent, getActualTarget, isElement } from '@ngstarter-ui/components/core';
5
5
  import { isPlatformBrowser, DOCUMENT } from '@angular/common';
@@ -59,6 +59,55 @@ const tilesShift = (order, currentVisualIndex, newVisualIndex) => {
59
59
  };
60
60
  const TILES_REORDER = new InjectionToken('TILES_REORDER', { factory: () => tilesShift });
61
61
 
62
+ const tolerance = 1;
63
+ function contains(outer, inner) {
64
+ return inner.left >= outer.left - tolerance && inner.right <= outer.right + tolerance &&
65
+ inner.top >= outer.top - tolerance && inner.bottom <= outer.bottom + tolerance;
66
+ }
67
+ function overlaps(a, b) {
68
+ return a.left < b.right - tolerance && a.right > b.left + tolerance &&
69
+ a.top < b.bottom - tolerance && a.bottom > b.top + tolerance;
70
+ }
71
+ /** Find a rectangle in the hovered rows that the dragged tile can trade with. */
72
+ function findTileGroup(slots, source, hovered, floating, columnGap, rowGap) {
73
+ const area = (rect) => (rect.width + columnGap) * (rect.height + rowGap);
74
+ const sourceArea = area(source);
75
+ let closest;
76
+ let closestDistance = Infinity;
77
+ for (const { tile, rect } of slots) {
78
+ const bounds = new DOMRectReadOnly(rect.left, rect.top, source.width, source.height);
79
+ const horizontalDistance = Math.abs(bounds.left - floating.left);
80
+ if (horizontalDistance > source.width / 4 || !contains(bounds, hovered) ||
81
+ (bounds.bottom > source.top + tolerance && bounds.top < source.bottom - tolerance))
82
+ continue;
83
+ const distance = Math.hypot(horizontalDistance, bounds.top - floating.top);
84
+ if (distance >= closestDistance)
85
+ continue;
86
+ const covered = slots.filter(slot => overlaps(bounds, slot.rect));
87
+ if (covered.length < 2 || covered.some(slot => !contains(bounds, slot.rect)))
88
+ continue;
89
+ // Include the grid gaps in each slot's area so holes do not count as covered cells.
90
+ const coveredArea = covered.reduce((sum, slot) => sum + area(slot.rect), 0);
91
+ if (Math.abs(sourceArea - coveredArea) > source.width + source.height)
92
+ continue;
93
+ closestDistance = distance;
94
+ closest = { anchor: tile, rect: bounds, tiles: new Set(covered.map(slot => slot.tile)) };
95
+ }
96
+ return closest;
97
+ }
98
+ function exchangeTileGroup(slots, dragged, source, group, rtl) {
99
+ // CSS Grid uses a dense layout, so order the new slots by their actual rows and columns.
100
+ const ordered = slots.map(({ tile, rect }) => {
101
+ if (tile === dragged)
102
+ return { tile, x: group.rect.left, y: group.rect.top };
103
+ if (group.tiles.has(tile)) {
104
+ return { tile, x: source.left + rect.left - group.rect.left, y: source.top + rect.top - group.rect.top };
105
+ }
106
+ return { tile, x: rect.left, y: rect.top };
107
+ }).sort((a, b) => Math.abs(a.y - b.y) > tolerance ? a.y - b.y : rtl ? b.x - a.x : a.x - b.x);
108
+ return new Map(ordered.map(({ tile }, index) => [tile, index]));
109
+ }
110
+
62
111
  class Tiles {
63
112
  reorder = inject(TILES_REORDER);
64
113
  el = injectElement();
@@ -77,15 +126,13 @@ class Tiles {
77
126
  orderChanged = output();
78
127
  layoutChanged = output();
79
128
  rearrangeTimer;
80
- lastSourceVisualIndex = null;
81
- lastTargetVisualIndex = null;
82
- lastSwapTime = 0;
83
- lastSwapX = 0;
84
- lastSwapY = 0;
129
+ pendingTarget;
130
+ lastRearrange;
85
131
  initialItems = null;
86
132
  isInitialized = false;
87
133
  isDragging = false;
88
134
  constructor() {
135
+ inject(DestroyRef).onDestroy(() => this.cancelPendingRearrange());
89
136
  effect(() => {
90
137
  const tiles = this.tiles();
91
138
  const currentOrder = this.order();
@@ -132,10 +179,7 @@ class Tiles {
132
179
  return layout.filter(item => item !== undefined);
133
180
  }
134
181
  onDragEnd(tile) {
135
- if (this.rearrangeTimer) {
136
- clearTimeout(this.rearrangeTimer);
137
- this.rearrangeTimer = null;
138
- }
182
+ this.cancelPendingRearrange();
139
183
  const currentItems = this.items();
140
184
  const currentOrder = this.order();
141
185
  const tiles = this.tiles();
@@ -159,9 +203,7 @@ class Tiles {
159
203
  console.warn('Tiles: New items length mismatch, skip emission', filteredNewItems.length, currentItems.length);
160
204
  }
161
205
  }
162
- this.lastSourceVisualIndex = null;
163
- this.lastTargetVisualIndex = null;
164
- this.lastSwapTime = 0;
206
+ this.lastRearrange = undefined;
165
207
  this.initialItems = null;
166
208
  this.isDragging = false;
167
209
  }
@@ -188,64 +230,55 @@ class Tiles {
188
230
  if (draggedVisualIndex === undefined || targetVisualIndex === undefined) {
189
231
  return;
190
232
  }
191
- const isMovingForward = draggedVisualIndex < targetVisualIndex;
192
- const areSameSize = draggedTile.width() === targetTile.width() && draggedTile.height() === targetTile.height();
193
233
  const columns = this.columns();
194
- const isFullWidth = draggedTile.width() === columns || (draggedTile.width() === 1 && columns === 1);
234
+ const isFullWidth = draggedTile.width() === columns;
195
235
  // Get the actual floating element's position
196
236
  const draggedWrapper = draggedTile.wrapper()?.nativeElement;
197
237
  if (!draggedWrapper) {
198
238
  return;
199
239
  }
200
240
  const floatingRect = draggedWrapper.getBoundingClientRect();
201
- // Check if the edge of the floating block has crossed the midpoint of the target tile
202
- const targetRect = element.getBoundingClientRect();
203
- const midX = targetRect.left + targetRect.width / 2;
204
- const midY = targetRect.top + targetRect.height / 2;
205
- const deltaX = Math.abs(targetRect.left - floatingRect.left);
206
- const deltaY = Math.abs(targetRect.top - floatingRect.top);
207
- let shouldRearrange = false;
208
- if (isFullWidth && !isMovingForward) {
209
- // Special logic for full-width tiles when moving up:
210
- // if the top edge of the dragged tile has passed the bottom third of the target tile
211
- if (floatingRect.top < targetRect.bottom - targetRect.height * 0.3) {
212
- shouldRearrange = true;
213
- }
214
- }
215
- else if (isFullWidth && isMovingForward) {
216
- // Special logic for full-width tiles when moving down:
217
- // if the bottom edge of the dragged tile has passed the top third of the target tile
218
- if (floatingRect.bottom > targetRect.top + targetRect.height * 0.3) {
219
- shouldRearrange = true;
220
- }
221
- }
222
- else if (deltaX > deltaY) {
223
- // Primarily horizontal movement
224
- const edgeX = isMovingForward ? floatingRect.right : floatingRect.left;
225
- const threshold = areSameSize ? (isMovingForward ? targetRect.left + targetRect.width * 0.2 : targetRect.right - targetRect.width * 0.2) : midX;
226
- if (isMovingForward ? edgeX >= threshold : edgeX <= threshold) {
227
- shouldRearrange = true;
228
- }
241
+ const sourceRect = draggedElement.getBoundingClientRect();
242
+ const hoveredRect = element.getBoundingClientRect();
243
+ const areSameSize = Math.abs(sourceRect.width - hoveredRect.width) < 1 &&
244
+ Math.abs(sourceRect.height - hoveredRect.height) < 1;
245
+ const canCoverGroup = !areSameSize && Math.abs(sourceRect.top - hoveredRect.top) >= 1 &&
246
+ hoveredRect.width <= sourceRect.width + 1 && hoveredRect.height <= sourceRect.height + 1;
247
+ const slots = canCoverGroup ? tiles.map(tile => ({ tile, rect: tile.element.getBoundingClientRect() })) : undefined;
248
+ const gridStyle = slots && getComputedStyle(this.el);
249
+ const group = slots && gridStyle && findTileGroup(slots, sourceRect, hoveredRect, floatingRect, parseFloat(gridStyle.columnGap) || 0, parseFloat(gridStyle.rowGap) || 0);
250
+ const targetRect = group?.rect ?? hoveredRect;
251
+ const vertical = Math.abs(sourceRect.top - targetRect.top) >= 1;
252
+ const forward = vertical ? sourceRect.top < targetRect.top : sourceRect.left < targetRect.left;
253
+ const start = vertical ? targetRect.top : targetRect.left;
254
+ const end = vertical ? targetRect.bottom : targetRect.right;
255
+ const fraction = isFullWidth ? 0.3 : group || areSameSize ? 0.2 : 0.5;
256
+ const edge = vertical
257
+ ? (forward ? floatingRect.bottom : floatingRect.top)
258
+ : (forward ? floatingRect.right : floatingRect.left);
259
+ const threshold = forward ? start + (end - start) * fraction : end - (end - start) * fraction;
260
+ if (forward ? edge < threshold : edge > threshold) {
261
+ this.cancelPendingRearrange();
262
+ return;
229
263
  }
230
- else {
231
- // Primarily vertical movement
232
- const edgeY = isMovingForward ? floatingRect.bottom : floatingRect.top;
233
- const threshold = areSameSize ? (isMovingForward ? targetRect.top + targetRect.height * 0.2 : targetRect.bottom - targetRect.height * 0.2) : midY;
234
- if (isMovingForward ? edgeY >= threshold : edgeY <= threshold) {
235
- shouldRearrange = true;
264
+ // After the layout changes, a different tile can move under the same pointer.
265
+ // Require the pointer to cross the new slot in the intended direction.
266
+ const last = this.lastRearrange;
267
+ if (last) {
268
+ const movement = vertical ? event.clientY - last.y : event.clientX - last.x;
269
+ if ((forward ? movement : -movement) < 10) {
270
+ this.cancelPendingRearrange();
271
+ return;
236
272
  }
237
273
  }
238
- if (!shouldRearrange) {
239
- return;
240
- }
241
274
  // Adjustment for full-width tiles to displace the entire row
242
- if (isFullWidth) {
275
+ if (isFullWidth && !group) {
243
276
  const targetTop = targetRect.top;
244
277
  let finalTargetVisualIndex = targetVisualIndex;
245
278
  tiles.forEach((t) => {
246
279
  const tIndex = order.get(t);
247
280
  if (tIndex !== undefined) {
248
- if (isMovingForward ? tIndex > finalTargetVisualIndex : tIndex < finalTargetVisualIndex) {
281
+ if (forward ? tIndex > finalTargetVisualIndex : tIndex < finalTargetVisualIndex) {
249
282
  const r = t.element.getBoundingClientRect();
250
283
  if (Math.abs(r.top - targetTop) < 5) {
251
284
  finalTargetVisualIndex = tIndex;
@@ -261,60 +294,37 @@ class Tiles {
261
294
  }
262
295
  }
263
296
  }
264
- // Recalculate size equality after potential adjustment
265
- const areSameSizeNow = draggedTile.width() === targetTile.width() && draggedTile.height() === targetTile.height();
266
- // Prevent bouncing: if we just swapped with this tile, don't swap back
267
- // unless the pointer has moved significantly in the opposite direction.
268
- const now = Date.now();
269
- if (now - this.lastSwapTime < 500 && this.lastTargetVisualIndex === draggedVisualIndex && this.lastSourceVisualIndex === targetVisualIndex) {
270
- const movementX = event.clientX - this.lastSwapX;
271
- const movementY = event.clientY - this.lastSwapY;
272
- // If we are moving in the same direction as the original swap, don't swap back
273
- const wasMovingForward = (this.lastSourceVisualIndex ?? 0) < (this.lastTargetVisualIndex ?? 0);
274
- if (deltaX > deltaY) {
275
- if (wasMovingForward ? movementX > -10 : movementX < 10) {
276
- return;
277
- }
278
- }
279
- else {
280
- if (wasMovingForward ? movementY > -10 : movementY < 10) {
281
- return;
282
- }
283
- }
284
- }
285
- // Skip if this is the exact same target we've already started to rearrange to
286
- if (this.rearrangeTimer && this.lastTargetVisualIndex === targetVisualIndex) {
297
+ const pendingTarget = group?.anchor ?? targetTile;
298
+ if (this.pendingTarget === pendingTarget)
287
299
  return;
288
- }
289
- if (this.rearrangeTimer) {
290
- clearTimeout(this.rearrangeTimer);
291
- }
292
- this.lastSourceVisualIndex = draggedVisualIndex;
293
- this.lastTargetVisualIndex = targetVisualIndex;
300
+ this.cancelPendingRearrange();
301
+ this.pendingTarget = pendingTarget;
302
+ const swap = (targetTile.element === element && areSameSize) ||
303
+ (isFullWidth && targetTile.width() === columns);
294
304
  this.rearrangeTimer = setTimeout(() => {
295
- const orderAtTimeOfExecution = this.order();
296
- let newOrder;
297
- this.lastSwapTime = Date.now();
298
- this.lastSwapX = event.clientX;
299
- this.lastSwapY = event.clientY;
300
- if (areSameSizeNow || (isFullWidth && targetTile.width() === 12)) {
301
- // Use swap for tiles of the same size or full-width tiles swapping with other full-width tiles
302
- newOrder = new Map(orderAtTimeOfExecution);
303
- newOrder.set(draggedTile, targetVisualIndex);
304
- newOrder.set(targetTile, draggedVisualIndex);
305
- }
306
- else {
307
- newOrder = this.reorder(orderAtTimeOfExecution, draggedVisualIndex, targetVisualIndex);
308
- }
305
+ this.rearrangeTimer = undefined;
306
+ this.pendingTarget = undefined;
307
+ if (this.element() !== draggedElement || this.order() !== order)
308
+ return;
309
+ const newOrder = group && slots
310
+ ? exchangeTileGroup(slots, draggedTile, sourceRect, group, gridStyle?.direction === 'rtl')
311
+ : (swap ? tilesSwap : this.reorder)(order, draggedVisualIndex, targetVisualIndex);
312
+ if (newOrder === order)
313
+ return;
314
+ this.lastRearrange = { x: event.clientX, y: event.clientY };
309
315
  this.order.set(new Map(newOrder));
310
316
  const result = new Map();
311
317
  tiles.forEach((tile, index) => {
312
318
  result.set(index, newOrder.get(tile) ?? index);
313
319
  });
314
320
  this.orderChange.emit(result);
315
- this.rearrangeTimer = null;
316
321
  }, 50);
317
322
  }
323
+ cancelPendingRearrange() {
324
+ clearTimeout(this.rearrangeTimer);
325
+ this.rearrangeTimer = undefined;
326
+ this.pendingTarget = undefined;
327
+ }
318
328
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: Tiles, deps: [], target: i0.ɵɵFactoryTarget.Component });
319
329
  static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.1.7", type: Tiles, isStandalone: true, selector: "ngs-tiles", inputs: { items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null }, gap: { classPropertyName: "gap", publicName: "gap", isSignal: true, isRequired: false, transformFunction: null }, columns: { classPropertyName: "columns", publicName: "columns", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { orderChange: "orderChange", orderChanged: "orderChanged", layoutChanged: "layoutChanged" }, host: { properties: { "style.--ngs-tiles-columns": "columns()", "style.grid-template-columns": "\"repeat(\" + columns() + \", 1fr)\"" }, classAttribute: "ngs-tiles" }, queries: [{ propertyName: "tiles", predicate: Tile, isSignal: true }], exportAs: ["ngsTiles"], ngImport: i0, template: '<ng-content/>', isInline: true, styles: [":host{--ngs-tiles-columns: 12;--ngs-tiles-row-height: 20px;--ngs-tiles-gap: calc(var(--spacing, .25rem) * 5);position:relative;-webkit-user-select:none;user-select:none;z-index:0;display:grid;grid-template-columns:repeat(var(--ngs-tiles-columns, 12),1fr);grid-auto-flow:dense;justify-items:stretch;gap:var(--ngs-tiles-gap);grid-auto-rows:minmax(var(--ngs-tiles-row-height),auto)}@media(max-width:639px){:host{--ngs-tiles-columns: 1 !important;grid-template-columns:1fr!important}}:host._dragged ngs-tile{pointer-events:auto}:host._dragged ngs-tile._dragged{pointer-events:none}:host._dragged ngs-tile>.t-wrapper{pointer-events:none;will-change:transform}:host._dragged ngs-tile>*{pointer-events:none}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
320
330
  }
@@ -335,7 +345,8 @@ class TileService {
335
345
  offset$ = new BehaviorSubject([NaN, NaN]);
336
346
  resize$ = inject(ResizeObserverService).observe(this.el);
337
347
  mutations$ = inject(MutationObserverService).observe(this.el, { childList: true });
338
- lastRect = null;
348
+ lastPosition = null;
349
+ lastOrder = new Map();
339
350
  position$ = combineLatest([
340
351
  this.offset$.pipe(distinctUntilChanged(arrayShallowEquals)),
341
352
  this.resize$.pipe(startWith(null)),
@@ -345,7 +356,7 @@ class TileService {
345
356
  init(element) {
346
357
  if (this.isBrowser && element) {
347
358
  this.sub.add(this.position$.subscribe(({ offset, order }) => {
348
- this.animate(element);
359
+ this.animate(element, order);
349
360
  this.setPosition(element, offset);
350
361
  this.setRect(element, offset);
351
362
  }));
@@ -354,16 +365,20 @@ class TileService {
354
365
  this.el.style.setProperty('position', 'relative');
355
366
  }
356
367
  }
357
- animate(element) {
368
+ animate(element, order) {
358
369
  const isDragging = !Number.isNaN(this.offset$.value[0]);
359
- const currentRect = this.el.getBoundingClientRect();
360
- if (isDragging || (element.style.position === 'fixed' && !element.style.transition.includes('top'))) {
361
- this.lastRect = currentRect;
370
+ // Measure relative to the grid so scrolling does not look like a reorder.
371
+ const currentPosition = { left: this.el.offsetLeft, top: this.el.offsetTop };
372
+ // Initial placement and loading-related reflows are not tile reorders.
373
+ const reordered = [...order].some(([tile, index]) => this.lastOrder.has(tile) && this.lastOrder.get(tile) !== index);
374
+ this.lastOrder = order;
375
+ if (!reordered || isDragging || (element.style.position === 'fixed' && !element.style.transition.includes('top'))) {
376
+ this.lastPosition = currentPosition;
362
377
  return;
363
378
  }
364
- if (this.lastRect) {
365
- const dx = this.lastRect.left - currentRect.left;
366
- const dy = this.lastRect.top - currentRect.top;
379
+ if (this.lastPosition) {
380
+ const dx = this.lastPosition.left - currentPosition.left;
381
+ const dy = this.lastPosition.top - currentPosition.top;
367
382
  if (dx !== 0 || dy !== 0) {
368
383
  element.style.setProperty('transition', 'none');
369
384
  element.style.setProperty('transform', `translate(${px(dx)}, ${px(dy)})`);
@@ -373,7 +388,7 @@ class TileService {
373
388
  element.style.removeProperty('transform');
374
389
  }
375
390
  }
376
- this.lastRect = currentRect;
391
+ this.lastPosition = currentPosition;
377
392
  }
378
393
  setOffset(offset) {
379
394
  this.offset$.next(offset);