{"version":3,"file":"index.mjs","names":[],"sources":["../src/style-gen.ts","../src/inspect-button.ts","../src/render-popup.ts","../src/colors.ts","../src/theme-colors.ts","../src/maplibre-gl-inspect.ts","../src/index.ts"],"sourcesContent":["import type {\n  SourceSpecification,\n  LayerSpecification,\n  StyleSpecification,\n  CircleLayerSpecification,\n  FillLayerSpecification,\n  LineLayerSpecification,\n  BackgroundLayerSpecification,\n} from 'maplibre-gl';\nimport type { Options } from './types';\n\nconst circleLayer = (\n  color: string,\n  source: string,\n  vectorLayer?: string | undefined,\n) => {\n  const layer: CircleLayerSpecification = {\n    id: [source, vectorLayer, 'circle'].join('_'),\n    source,\n    type: 'circle',\n    paint: {\n      'circle-color': color,\n      'circle-radius': 2,\n    },\n    filter: ['==', '$type', 'Point'],\n  };\n  if (vectorLayer) {\n    layer['source-layer'] = vectorLayer;\n  }\n  return layer;\n};\nconst polygonLayer = (\n  color: string,\n  outlineColor: string,\n  source: string,\n  vectorLayer?: string | undefined,\n) => {\n  const layer: FillLayerSpecification = {\n    id: [source, vectorLayer, 'polygon'].join('_'),\n    source,\n    type: 'fill',\n    paint: {\n      'fill-antialias': true,\n      'fill-color': color,\n      'fill-outline-color': outlineColor,\n    },\n    filter: ['==', '$type', 'Polygon'],\n  };\n  if (vectorLayer) {\n    layer['source-layer'] = vectorLayer;\n  }\n  return layer;\n};\nconst lineLayer = (\n  color: string,\n  source: string,\n  vectorLayer?: string | undefined,\n) => {\n  const layer: LineLayerSpecification = {\n    id: [source, vectorLayer, 'line'].join('_'),\n    source,\n    layout: {\n      'line-join': 'round',\n      'line-cap': 'round',\n    },\n    type: 'line',\n    paint: {\n      'line-color': color,\n    },\n    filter: ['==', '$type', 'LineString'],\n  };\n  if (vectorLayer) {\n    layer['source-layer'] = vectorLayer;\n  }\n  return layer;\n};\n\nconst generateColoredLayers = (\n  sources: Options['sources'],\n  assignLayerColor: Options['assignLayerColor'],\n): (\n  | FillLayerSpecification\n  | LineLayerSpecification\n  | CircleLayerSpecification\n)[] => {\n  const polyLayers: FillLayerSpecification[] = [];\n  const circleLayers: CircleLayerSpecification[] = [];\n  const lineLayers: LineLayerSpecification[] = [];\n\n  const alphaColors = (layerId: string) => {\n    const color = assignLayerColor.bind(null, layerId);\n    const obj = {\n      circle: color(0.8),\n      line: color(0.6),\n      polygon: color(0.3),\n      polygonOutline: color(0.6),\n      default: color(1),\n    };\n    return obj;\n  };\n\n  Object.keys(sources).forEach((sourceId) => {\n    const layers = sources[`${sourceId}`] as string[];\n\n    if (!layers || layers.length === 0) {\n      const colors = alphaColors(sourceId);\n      circleLayers.push(circleLayer(colors.circle, sourceId));\n      lineLayers.push(lineLayer(colors.line, sourceId));\n      polyLayers.push(\n        polygonLayer(colors.polygon, colors.polygonOutline, sourceId),\n      );\n    } else {\n      layers.forEach((layer: string) => {\n        const colors = alphaColors(layer);\n\n        circleLayers.push(circleLayer(colors.circle, sourceId, layer));\n        lineLayers.push(lineLayer(colors.line, sourceId, layer));\n        polyLayers.push(\n          polygonLayer(colors.polygon, colors.polygonOutline, sourceId, layer),\n        );\n      });\n    }\n  });\n\n  return [...polyLayers, ...lineLayers, ...circleLayers];\n};\n\nconst generateInspectStyle = (\n  originalMapStyle: StyleSpecification,\n  coloredLayers: LayerSpecification[],\n  opts: any,\n): StyleSpecification => {\n  opts = Object.assign(\n    {\n      backgroundColor: '#fff',\n    },\n    opts,\n  );\n\n  const backgroundLayer: BackgroundLayerSpecification = {\n    id: 'background',\n    type: 'background',\n    paint: {\n      'background-color': opts.backgroundColor,\n    },\n  };\n\n  const sources = {} as {\n    [_: string]: SourceSpecification;\n  };\n  Object.keys(originalMapStyle.sources).forEach((sourceId) => {\n    const source = originalMapStyle.sources[`${sourceId}`];\n    if (source && (source.type === 'vector' || source.type === 'geojson')) {\n      sources[`${sourceId}`] = source;\n    }\n  });\n\n  return {\n    ...originalMapStyle,\n    layers: [backgroundLayer, ...coloredLayers],\n    sources,\n  };\n};\n\nexport { generateInspectStyle, generateColoredLayers };\n","class InspectButton {\n  private _btn: HTMLButtonElement;\n  public elem: HTMLDivElement;\n\n  constructor(options: any) {\n    options = Object.assign(\n      {\n        show: true,\n        onToggle: () => {},\n      },\n      options,\n    );\n\n    this._btn = this.button();\n    this._btn.onclick = options.onToggle;\n    this.elem = this.container(this._btn, options.show);\n  }\n\n  private container(child: Node, show: boolean): HTMLDivElement {\n    const container = document.createElement('div');\n    container.className = 'maplibregl-ctrl maplibregl-ctrl-group';\n    container.appendChild(child);\n    if (!show) {\n      container.style.display = 'none';\n    }\n    return container;\n  }\n\n  private button(): HTMLButtonElement {\n    const btn = document.createElement('button');\n    btn.className = 'maplibregl-ctrl-icon maplibregl-ctrl-inspect';\n    btn.type = 'button';\n    btn.ariaLabel = 'Inspect';\n    return btn;\n  }\n\n  public setInspectIcon(): void {\n    this._btn.className = 'maplibregl-ctrl-icon maplibregl-ctrl-inspect';\n  }\n\n  public setMapIcon(): void {\n    this._btn.className = 'maplibregl-ctrl-icon maplibregl-ctrl-map';\n  }\n}\n\nexport { InspectButton };\n","import type { RenderPopupFeature, RenderPopupProperty } from './types';\n\nconst displayValue = (\n  value: RenderPopupProperty[keyof RenderPopupProperty],\n) => {\n  if (typeof value === 'undefined' || value === null) return value;\n  if (value instanceof Date) return value.toLocaleString();\n  if (\n    typeof value === 'object' ||\n    typeof value === 'number' ||\n    typeof value === 'string'\n  )\n    return value.toString();\n  return value;\n};\n\nconst renderProperty = <\n  T extends RenderPopupProperty[keyof RenderPopupProperty],\n>(\n  propertyName: string,\n  property: T,\n) => {\n  return (\n    `${\n      '<div class=\"maplibregl-inspect-property\">' +\n      '<div class=\"maplibregl-inspect-property-name\">'\n    }${propertyName}</div>` +\n    `<div class=\"maplibregl-inspect-property-value\">${displayValue(\n      property,\n    )}</div>` +\n    '</div>'\n  );\n};\n\nconst renderLayer = (layerId: string) => {\n  return `<div class=\"maplibregl-inspect-layer\">${layerId}</div>`;\n};\n\nconst renderProperties = (feature: RenderPopupFeature) => {\n  const sourceProperty = renderLayer(\n    feature.layer['source-layer'] || feature.layer.source,\n  );\n  const typeProperty = renderProperty<string>('$type', feature.geometry.type);\n  const properties = Object.keys(feature.properties).map((propertyName) =>\n    renderProperty(propertyName, feature.properties[`${propertyName}`]),\n  );\n  return [sourceProperty, typeProperty].concat(properties).join('');\n};\n\nconst renderFeatures = (features: RenderPopupFeature[]) => {\n  return features\n    .map(\n      (ft: RenderPopupFeature) =>\n        `<div class=\"maplibregl-inspect-feature\">${renderProperties(ft)}</div>`,\n    )\n    .join('');\n};\n\nconst renderPopup = (features: RenderPopupFeature[]) => {\n  return `<div class=\"maplibregl-inspect-popup\">${renderFeatures(\n    features,\n  )}</div>`;\n};\n\nexport { renderPopup };\n","import randomColor from 'randomcolor';\n\n/**\n * Assign a color to a unique layer ID and also considering\n * common layer names such as water or wood.\n *\n * @param {string} layerId - Unique layer ID\n * @param {number} alpha - Alpha value for the color\n * @returns {string} Unique random for the layer ID\n */\nconst brightColor = (layerId: string, alpha?: number): string => {\n  let luminosity: 'bright' | 'dark' = 'bright';\n  let hue: string | undefined = undefined;\n\n  if (/water|ocean|lake|sea|river/.test(layerId)) {\n    hue = 'blue';\n  }\n\n  if (/state|country|place/.test(layerId)) {\n    hue = 'pink';\n  }\n\n  if (/road|highway|transport|streets/.test(layerId)) {\n    hue = 'orange';\n  }\n\n  if (/contour|building/.test(layerId)) {\n    hue = 'monochrome';\n  }\n\n  if (/building/.test(layerId)) {\n    luminosity = 'dark';\n  }\n\n  if (/contour|landuse/.test(layerId)) {\n    hue = 'yellow';\n  }\n\n  if (/wood|forest|park|landcover|land/.test(layerId)) {\n    hue = 'green';\n  }\n\n  const rgb = randomColor({\n    luminosity,\n    hue,\n    seed: layerId,\n    format: 'rgbArray',\n  });\n\n  const rgba = `${rgb},${alpha || 1}`;\n  return `rgba(${rgba})`;\n};\n\nexport { brightColor };\n","import type { ThemeColors } from './types';\n\nexport const DEFAULT_LIGHT_COLORS: ThemeColors = {\n  popupText: '#333333',\n  popupBg: '#ffffff',\n  popupBorder: '#e5e7eb',\n  buttonIcon: '#333333',\n  ctrlBg: '#ffffff',\n  inspectBackground: '#ffffff',\n};\n\nexport const DEFAULT_DARK_COLORS: ThemeColors = {\n  popupText: '#e5e7eb',\n  popupBg: '#1f2937',\n  popupBorder: '#4b5563',\n  buttonIcon: '#e5e7eb',\n  ctrlBg: '#374151',\n  inspectBackground: '#1f2937',\n};\n","import maplibregl from 'maplibre-gl';\nimport type {\n  Map,\n  Popup,\n  PointLike,\n  MapMouseEvent,\n  MapSourceDataEvent,\n  StyleSpecification,\n} from 'maplibre-gl';\nimport type { Options, RenderPopupFeature, Theme, ThemeColors } from './types';\nimport './maplibre-gl-inspect.css';\n\nimport { generateInspectStyle, generateColoredLayers } from './style-gen';\nimport { InspectButton } from './inspect-button';\nimport { renderPopup } from './render-popup';\nimport { brightColor } from './colors';\nimport { DEFAULT_LIGHT_COLORS, DEFAULT_DARK_COLORS } from './theme-colors';\n\n/** Internal MapLibre GL types for accessing private style APIs */\ninterface SourceInternal {\n  vectorLayerIds?: string[];\n  type?: string;\n}\n\ninterface TileManagerInternal {\n  getSource(): SourceInternal;\n}\n\ninterface StyleInternal {\n  tileManagers: Record<string, TileManagerInternal>;\n}\n\nconst isInspectStyle = (style: StyleSpecification): boolean => {\n  return !!(\n    style.metadata &&\n    'maplibregl-inspect:inspect' in (style.metadata as Record<string, unknown>)\n  );\n};\n\nconst markInspectStyle = (style: StyleSpecification): StyleSpecification => {\n  const updatedStyle = {\n    ...style,\n    metadata: Object.assign({}, style.metadata, {\n      'maplibregl-inspect:inspect': true,\n    }),\n  };\n  return updatedStyle;\n};\n\nclass MaplibreInspect {\n  private _map: Map | undefined;\n  private _popup: Popup | null;\n  private _popupBlocked = false;\n  private _showInspectMap: boolean;\n  private _originalStyle: StyleSpecification | null;\n  private _toggle: InspectButton;\n  public options: Options;\n  public sources: Options['sources'];\n  public assignLayerColor: Options['assignLayerColor'];\n  private _currentTheme: Theme;\n  private readonly _mediaQuery: MediaQueryList | null;\n  private readonly _lightColors: ThemeColors;\n  private readonly _darkColors: ThemeColors;\n\n  constructor(options?: Partial<Options>) {\n    if (!(this instanceof MaplibreInspect)) {\n      throw new Error(\n        'MaplibreInspect needs to be called with the new keyword',\n      );\n    }\n\n    let popup: Popup | null = null;\n    if (maplibregl) {\n      popup = new maplibregl.Popup({\n        closeButton: false,\n        closeOnClick: false,\n      });\n    } else if (!options?.popup) {\n      console.error(\n        'Maplibre GL JS can not be found. Make sure to include it or pass an initialized MaplibreGL Popup to MaplibreInspect if you are using moduleis.',\n      );\n    }\n\n    const defaults: Options = {\n      showInspectMap: false,\n      showInspectButton: true,\n      showInspectMapPopup: true,\n      showMapPopup: false,\n      showMapPopupOnHover: true,\n      showInspectMapPopupOnHover: false,\n      blockHoverPopupOnClick: false,\n      backgroundColor: '#fff',\n      assignLayerColor: brightColor,\n      buildInspectStyle: generateInspectStyle,\n      renderPopup,\n      popup,\n      selectThreshold: 5,\n      useInspectStyle: true,\n      queryParameters: {},\n      sources: {},\n      toggleCallback(showInspect: boolean) {\n        console.log('Inspector status?: ', showInspect);\n      },\n    };\n    this.options = Object.assign(defaults, options);\n\n    this.sources = this.options.sources;\n    this.assignLayerColor = this.options.assignLayerColor;\n    this.toggleInspector = this.toggleInspector.bind(this);\n    this._popup = this.options.popup;\n    this._popupBlocked = false;\n    this._showInspectMap = this.options.showInspectMap;\n    this._onSourceChange = this._onSourceChange.bind(this);\n    this._onMouseMove = this._onMouseMove.bind(this);\n    this._onRightClick = this._onRightClick.bind(this);\n    this._onStyleChange = this._onStyleChange.bind(this);\n\n    this._currentTheme = this.options.theme ?? 'system';\n    this._lightColors = {\n      ...DEFAULT_LIGHT_COLORS,\n      ...this.options.lightColors,\n    };\n    this._darkColors = { ...DEFAULT_DARK_COLORS, ...this.options.darkColors };\n\n    if (\n      this._currentTheme === 'system' &&\n      typeof window !== 'undefined' &&\n      window.matchMedia\n    ) {\n      this._mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');\n      this._mediaQuery.addEventListener('change', this._onSystemThemeChange);\n    } else {\n      this._mediaQuery = null;\n    }\n\n    this._applyTheme();\n\n    this._originalStyle = null;\n    this._toggle = new InspectButton({\n      show: this.options.showInspectButton,\n      onToggle: this.toggleInspector.bind(this),\n    });\n  }\n\n  private _inspectStyle(): StyleSpecification {\n    let style = this._map?.getStyle();\n    if (this._map) {\n      const coloredLayers = generateColoredLayers(\n        this.sources,\n        this.assignLayerColor,\n      );\n      style = this.options.buildInspectStyle(\n        this._map.getStyle(),\n        coloredLayers,\n        {\n          backgroundColor: this.options.backgroundColor,\n        },\n      );\n    }\n    return style as StyleSpecification;\n  }\n\n  private _onSourceChange(e: MapSourceDataEvent) {\n    const sources = this.sources;\n    if (this._map) {\n      const map = this._map;\n      const mapStyle = map.getStyle();\n      const mapStyleSourcesNames = Object.keys(mapStyle.sources);\n      const previousSources = Object.assign({}, sources);\n\n      //NOTE: This heavily depends on the internal API of Maplibre GL\n      //so this breaks between Maplibre GL JS releases\n      if (e.isSourceLoaded) {\n        const { tileManagers } = map.style as unknown as StyleInternal;\n        for (const sourceId of Object.keys(tileManagers)) {\n          const source = tileManagers[sourceId]?.getSource();\n          if (source?.vectorLayerIds) {\n            sources[sourceId] = source.vectorLayerIds;\n          } else if (source?.type === 'geojson') {\n            sources[sourceId] = [];\n          }\n        }\n\n        Object.keys(sources).forEach((sourceId) => {\n          if (mapStyleSourcesNames.indexOf(sourceId) === -1) {\n            delete sources[`${sourceId}`];\n          }\n        });\n\n        if (\n          JSON.stringify(previousSources) !== JSON.stringify(sources) &&\n          Object.keys(sources).length > 0\n        ) {\n          this.render();\n        }\n      }\n    }\n  }\n\n  private _onStyleChange() {\n    const style = this._map?.getStyle();\n    if (style && !isInspectStyle(style)) {\n      this._originalStyle = style;\n    }\n  }\n\n  private _onRightClick() {\n    if (\n      !this.options.showMapPopupOnHover &&\n      !this.options.showInspectMapPopupOnHover &&\n      !this.options.blockHoverPopupOnClick\n    ) {\n      if (this._popup) this._popup.remove();\n    }\n  }\n\n  private _onMouseMove(e: MouseEvent | MapMouseEvent) {\n    if (this._showInspectMap) {\n      if (!this.options.showInspectMapPopup) return;\n      if (e.type === 'mousemove' && !this.options.showInspectMapPopupOnHover)\n        return;\n      if (\n        e.type === 'click' &&\n        this.options.showInspectMapPopupOnHover &&\n        this.options.blockHoverPopupOnClick\n      ) {\n        this._popupBlocked = !this._popupBlocked;\n      }\n    } else {\n      if (!this.options.showMapPopup) return;\n      if (e.type === 'mousemove' && !this.options.showMapPopupOnHover) return;\n      if (\n        e.type === 'click' &&\n        this.options.showMapPopupOnHover &&\n        this.options.blockHoverPopupOnClick\n      ) {\n        this._popupBlocked = !this._popupBlocked;\n      }\n    }\n\n    if (!this._popupBlocked && this._map) {\n      let queryBox: PointLike | [PointLike, PointLike];\n      if (this.options.selectThreshold === 0) {\n        queryBox = (e as MapMouseEvent).point;\n      } else {\n        // set a bbox around the pointer\n        queryBox = [\n          [\n            (e as MapMouseEvent).point.x - this.options.selectThreshold,\n            (e as MapMouseEvent).point.y + this.options.selectThreshold,\n          ], // bottom left (SW)\n          [\n            (e as MapMouseEvent).point.x + this.options.selectThreshold,\n            (e as MapMouseEvent).point.y - this.options.selectThreshold,\n          ], // top right (NE)\n        ];\n      }\n      const features =\n        this._map.queryRenderedFeatures(\n          queryBox,\n          this.options.queryParameters,\n        ) || [];\n\n      this._map.getCanvas().style.cursor = features.length ? 'pointer' : '';\n\n      if (features.length > 0 && this._popup instanceof maplibregl.Popup) {\n        this._popup.setLngLat((e as MapMouseEvent).lngLat);\n        const renderedPopup = this.options.renderPopup(\n          features as unknown as RenderPopupFeature[],\n        );\n        if (typeof renderedPopup === 'string') {\n          this._popup.setHTML(renderedPopup);\n        } else {\n          this._popup.setDOMContent(renderedPopup);\n        }\n        this._popup.addTo(this._map);\n      } else {\n        this._popup?.remove();\n      }\n    }\n  }\n\n  public toggleInspector(): void {\n    this._showInspectMap = !this._showInspectMap;\n    this.options.toggleCallback(this._showInspectMap);\n    this.render();\n  }\n\n  get theme(): Theme {\n    return this._currentTheme;\n  }\n\n  public setTheme(theme: Theme): void {\n    const previousTheme = this._currentTheme;\n    this._currentTheme = theme;\n\n    if (previousTheme === 'system' && theme !== 'system' && this._mediaQuery) {\n      this._mediaQuery.removeEventListener('change', this._onSystemThemeChange);\n    } else if (\n      previousTheme !== 'system' &&\n      theme === 'system' &&\n      this._mediaQuery\n    ) {\n      this._mediaQuery.addEventListener('change', this._onSystemThemeChange);\n    }\n\n    this._applyTheme();\n  }\n\n  private _onSystemThemeChange = (): void => {\n    if (this._currentTheme === 'system') {\n      this._applyTheme();\n    }\n  };\n\n  private _getResolvedTheme(): 'light' | 'dark' {\n    if (this._currentTheme === 'system') {\n      if (this._mediaQuery) {\n        return this._mediaQuery.matches ? 'dark' : 'light';\n      }\n      return 'light';\n    }\n    return this._currentTheme;\n  }\n\n  private _applyTheme(): void {\n    const resolved = this._getResolvedTheme();\n    const colors = resolved === 'dark' ? this._darkColors : this._lightColors;\n\n    document.documentElement.style.setProperty(\n      '--inspect-popup-text',\n      colors.popupText,\n    );\n    document.documentElement.style.setProperty(\n      '--inspect-popup-bg',\n      colors.popupBg,\n    );\n    document.documentElement.style.setProperty(\n      '--inspect-popup-border',\n      colors.popupBorder,\n    );\n    document.documentElement.style.setProperty(\n      '--inspect-button-icon',\n      colors.buttonIcon,\n    );\n    document.documentElement.style.setProperty(\n      '--inspect-ctrl-bg',\n      colors.ctrlBg,\n    );\n    document.documentElement.style.setProperty(\n      '--inspect-background',\n      colors.inspectBackground,\n    );\n\n    if (this._currentTheme === 'system') {\n      document.documentElement.removeAttribute('data-inspect-theme');\n    } else {\n      document.documentElement.setAttribute('data-inspect-theme', resolved);\n    }\n  }\n\n  public render(): void {\n    if (this._showInspectMap) {\n      if (this.options.useInspectStyle) {\n        const inspectedStyle = this._inspectStyle();\n        this._map?.setStyle(\n          markInspectStyle(inspectedStyle as StyleSpecification),\n        );\n      }\n      this._toggle.setMapIcon();\n    }\n    if (!this._showInspectMap && this._originalStyle) {\n      if (this.options.useInspectStyle) {\n        this._map?.setStyle(this._originalStyle);\n      }\n      if (this._popup) this._popup.remove();\n      this._toggle.setInspectIcon();\n    }\n  }\n\n  public onAdd(map: Map) {\n    this._map = map;\n\n    // if sources have already been passed as options\n    // we do not need to figure out the sources ourselves\n    if (Object.keys(this.sources).length === 0) {\n      // map.on('tiledata', this._onSourceChange);\n      map.on('sourcedata', this._onSourceChange);\n    }\n\n    map.on('styledata', this._onStyleChange);\n    map.on('load', this._onStyleChange);\n    map.on('mousemove', this._onMouseMove);\n    map.on('click', this._onMouseMove);\n    map.on('contextmenu', this._onRightClick);\n    return this._toggle.elem;\n  }\n\n  public onRemove() {\n    this._map?.off('styledata', this._onStyleChange);\n    this._map?.off('load', this._onStyleChange);\n    // this._map?.off('tiledata', this._onSourceChange);\n    this._map?.off('sourcedata', this._onSourceChange);\n    this._map?.off('mousemove', this._onMouseMove);\n    this._map?.off('click', this._onMouseMove);\n    this._map?.off('contextmenu', this._onRightClick);\n\n    if (this._mediaQuery) {\n      this._mediaQuery.removeEventListener('change', this._onSystemThemeChange);\n    }\n\n    document.documentElement.removeAttribute('data-inspect-theme');\n\n    const elem = this._toggle.elem;\n    elem.parentNode?.removeChild(elem);\n    this._map = undefined;\n  }\n}\n\nexport { MaplibreInspect };\n","import { MaplibreInspect } from './maplibre-gl-inspect';\n\nexport { MaplibreInspect };\nexport { DEFAULT_LIGHT_COLORS, DEFAULT_DARK_COLORS } from './theme-colors';\nexport type {\n  Options,\n  RenderPopupFeature,\n  RenderPopupProperty,\n  Theme,\n  ThemeColors,\n} from './types';\nexport default MaplibreInspect;\n"],"mappings":";;;AAWA,MAAM,eACJ,OACA,QACA,gBACG;CACH,MAAM,QAAkC;EACtC,IAAI;GAAC;GAAQ;GAAa;GAAS,CAAC,KAAK,IAAI;EAC7C;EACA,MAAM;EACN,OAAO;GACL,gBAAgB;GAChB,iBAAiB;GAClB;EACD,QAAQ;GA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