@sakuzu/maplibre-gl-draw 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/LICENSE +661 -0
- package/README.ja.md +248 -0
- package/README.md +255 -0
- package/THIRD_PARTY_NOTICES.md +275 -0
- package/dist/api/api.d.ts +1259 -0
- package/dist/api/api.js +86 -0
- package/dist/api/context.d.ts +173 -0
- package/dist/api/context.js +193 -0
- package/dist/api/display-api.d.ts +1 -0
- package/dist/api/display-api.js +23 -0
- package/dist/api/event-api.d.ts +13 -0
- package/dist/api/event-api.js +17 -0
- package/dist/api/extension-api.d.ts +46 -0
- package/dist/api/extension-api.js +85 -0
- package/dist/api/feature-api.d.ts +11 -0
- package/dist/api/feature-api.js +101 -0
- package/dist/api/geometry/apply.d.ts +51 -0
- package/dist/api/geometry/apply.js +114 -0
- package/dist/api/geometry/boolean.d.ts +28 -0
- package/dist/api/geometry/boolean.js +65 -0
- package/dist/api/geometry/buffer.d.ts +11 -0
- package/dist/api/geometry/buffer.js +105 -0
- package/dist/api/geometry/split.d.ts +16 -0
- package/dist/api/geometry/split.js +75 -0
- package/dist/api/geometry/targets.d.ts +76 -0
- package/dist/api/geometry/targets.js +158 -0
- package/dist/api/geometry/types.d.ts +31 -0
- package/dist/api/geometry/types.js +3 -0
- package/dist/api/geometry-operations.d.ts +162 -0
- package/dist/api/geometry-operations.js +94 -0
- package/dist/api/group-api.d.ts +10 -0
- package/dist/api/group-api.js +78 -0
- package/dist/api/import-export/constants.d.ts +29 -0
- package/dist/api/import-export/constants.js +40 -0
- package/dist/api/import-export/embedded-file.d.ts +13 -0
- package/dist/api/import-export/embedded-file.js +31 -0
- package/dist/api/import-export/file-name.d.ts +10 -0
- package/dist/api/import-export/file-name.js +20 -0
- package/dist/api/import-export/format-detection.d.ts +12 -0
- package/dist/api/import-export/format-detection.js +29 -0
- package/dist/api/import-export/geojson-export.d.ts +19 -0
- package/dist/api/import-export/geojson-export.js +262 -0
- package/dist/api/import-export/geojson-import.d.ts +34 -0
- package/dist/api/import-export/geojson-import.js +538 -0
- package/dist/api/import-export/geometry-validation.d.ts +20 -0
- package/dist/api/import-export/geometry-validation.js +107 -0
- package/dist/api/import-export/image-import.d.ts +12 -0
- package/dist/api/import-export/image-import.js +53 -0
- package/dist/api/import-export/index.d.ts +9 -0
- package/dist/api/import-export/index.js +107 -0
- package/dist/api/import-export/native-format.d.ts +15 -0
- package/dist/api/import-export/native-format.js +126 -0
- package/dist/api/import-export/native-validation.d.ts +28 -0
- package/dist/api/import-export/native-validation.js +212 -0
- package/dist/api/import-export/own-property.d.ts +10 -0
- package/dist/api/import-export/own-property.js +19 -0
- package/dist/api/import-export/style-validation.d.ts +27 -0
- package/dist/api/import-export/style-validation.js +49 -0
- package/dist/api/import-export/types.d.ts +26 -0
- package/dist/api/import-export/types.js +3 -0
- package/dist/api/index.d.ts +15 -0
- package/dist/api/index.js +3 -0
- package/dist/api/input-api.d.ts +158 -0
- package/dist/api/input-api.js +144 -0
- package/dist/api/instance-api.d.ts +38 -0
- package/dist/api/instance-api.js +136 -0
- package/dist/api/layer-api.d.ts +12 -0
- package/dist/api/layer-api.js +62 -0
- package/dist/api/selection-api.d.ts +7 -0
- package/dist/api/selection-api.js +78 -0
- package/dist/api/snapping-api.d.ts +125 -0
- package/dist/api/snapping-api.js +50 -0
- package/dist/api/topology-api.d.ts +30 -0
- package/dist/api/topology-api.js +16 -0
- package/dist/api/tracing-api.d.ts +31 -0
- package/dist/api/tracing-api.js +16 -0
- package/dist/dispatcher/hit-test/box-strategies.d.ts +19 -0
- package/dist/dispatcher/hit-test/box-strategies.js +275 -0
- package/dist/dispatcher/hit-test/box-strategy.d.ts +59 -0
- package/dist/dispatcher/hit-test/box-strategy.js +37 -0
- package/dist/dispatcher/hit-test/globe-shape.d.ts +46 -0
- package/dist/dispatcher/hit-test/globe-shape.js +70 -0
- package/dist/dispatcher/hit-test/index.d.ts +14 -0
- package/dist/dispatcher/hit-test/index.js +9 -0
- package/dist/dispatcher/hit-test/local-frame.d.ts +77 -0
- package/dist/dispatcher/hit-test/local-frame.js +112 -0
- package/dist/dispatcher/hit-test/segment-grid.d.ts +32 -0
- package/dist/dispatcher/hit-test/segment-grid.js +79 -0
- package/dist/dispatcher/hit-test/service.d.ts +120 -0
- package/dist/dispatcher/hit-test/service.js +333 -0
- package/dist/dispatcher/hit-test/strategies/base.d.ts +136 -0
- package/dist/dispatcher/hit-test/strategies/base.js +66 -0
- package/dist/dispatcher/hit-test/strategies/circle.d.ts +10 -0
- package/dist/dispatcher/hit-test/strategies/circle.js +56 -0
- package/dist/dispatcher/hit-test/strategies/image.d.ts +22 -0
- package/dist/dispatcher/hit-test/strategies/image.js +115 -0
- package/dist/dispatcher/hit-test/strategies/index.d.ts +11 -0
- package/dist/dispatcher/hit-test/strategies/index.js +10 -0
- package/dist/dispatcher/hit-test/strategies/line.d.ts +17 -0
- package/dist/dispatcher/hit-test/strategies/line.js +30 -0
- package/dist/dispatcher/hit-test/strategies/multi.d.ts +44 -0
- package/dist/dispatcher/hit-test/strategies/multi.js +141 -0
- package/dist/dispatcher/hit-test/strategies/point.d.ts +20 -0
- package/dist/dispatcher/hit-test/strategies/point.js +29 -0
- package/dist/dispatcher/hit-test/strategies/polygon.d.ts +52 -0
- package/dist/dispatcher/hit-test/strategies/polygon.js +138 -0
- package/dist/dispatcher/hit-test/topmost.d.ts +48 -0
- package/dist/dispatcher/hit-test/topmost.js +157 -0
- package/dist/dispatcher/hit-test/visibility-lookup.d.ts +23 -0
- package/dist/dispatcher/hit-test/visibility-lookup.js +40 -0
- package/dist/dispatcher/index.d.ts +15 -0
- package/dist/dispatcher/index.js +3 -0
- package/dist/dispatcher/input-router.d.ts +1 -0
- package/dist/dispatcher/input-router.js +288 -0
- package/dist/dispatcher/normalizer.d.ts +1 -0
- package/dist/dispatcher/normalizer.js +513 -0
- package/dist/dispatcher/types.d.ts +144 -0
- package/dist/dispatcher/types.js +15 -0
- package/dist/display/chunk-set.d.ts +24 -0
- package/dist/display/chunk-set.js +533 -0
- package/dist/display/chunk.d.ts +1 -0
- package/dist/display/chunk.js +104 -0
- package/dist/display/columnar/index.d.ts +12 -0
- package/dist/display/columnar/index.js +13 -0
- package/dist/display/columnar/prepare.d.ts +42 -0
- package/dist/display/columnar/prepare.js +116 -0
- package/dist/display/columnar/source.d.ts +1 -0
- package/dist/display/columnar/source.js +531 -0
- package/dist/display/columnar/table.d.ts +1 -0
- package/dist/display/columnar/table.js +471 -0
- package/dist/display/columnar/types.d.ts +223 -0
- package/dist/display/columnar/types.js +3 -0
- package/dist/display/dataset.d.ts +2 -0
- package/dist/display/dataset.js +891 -0
- package/dist/display/index.d.ts +13 -0
- package/dist/display/index.js +3 -0
- package/dist/display/interaction.d.ts +1 -0
- package/dist/display/interaction.js +90 -0
- package/dist/display/manager.d.ts +1 -0
- package/dist/display/manager.js +440 -0
- package/dist/display/packed-rtree.d.ts +1 -0
- package/dist/display/packed-rtree.js +244 -0
- package/dist/display/partition.d.ts +1 -0
- package/dist/display/partition.js +226 -0
- package/dist/display/provider.d.ts +1 -0
- package/dist/display/provider.js +342 -0
- package/dist/display/retained.d.ts +40 -0
- package/dist/display/retained.js +898 -0
- package/dist/display/selection.d.ts +13 -0
- package/dist/display/selection.js +226 -0
- package/dist/display/source.d.ts +1 -0
- package/dist/display/source.js +119 -0
- package/dist/display/spatial.d.ts +1 -0
- package/dist/display/spatial.js +71 -0
- package/dist/display/style.d.ts +1 -0
- package/dist/display/style.js +126 -0
- package/dist/display/thinning.d.ts +65 -0
- package/dist/display/thinning.js +910 -0
- package/dist/display/triangulation.d.ts +1 -0
- package/dist/display/triangulation.js +0 -0
- package/dist/display/types.d.ts +561 -0
- package/dist/display/types.js +43 -0
- package/dist/extension/feature-handler.d.ts +182 -0
- package/dist/extension/feature-handler.js +3 -0
- package/dist/extension/index.d.ts +9 -0
- package/dist/extension/index.js +3 -0
- package/dist/extension/renderers.d.ts +208 -0
- package/dist/extension/renderers.js +3 -0
- package/dist/geometry/angle.d.ts +47 -0
- package/dist/geometry/angle.js +44 -0
- package/dist/geometry/bbox.d.ts +48 -0
- package/dist/geometry/bbox.js +83 -0
- package/dist/geometry/boolean.d.ts +162 -0
- package/dist/geometry/boolean.js +331 -0
- package/dist/geometry/buffer.d.ts +72 -0
- package/dist/geometry/buffer.js +218 -0
- package/dist/geometry/circle.d.ts +55 -0
- package/dist/geometry/circle.js +107 -0
- package/dist/geometry/coords.d.ts +97 -0
- package/dist/geometry/coords.js +149 -0
- package/dist/geometry/distance.d.ts +79 -0
- package/dist/geometry/distance.js +111 -0
- package/dist/geometry/errors.d.ts +74 -0
- package/dist/geometry/errors.js +104 -0
- package/dist/geometry/index.d.ts +28 -0
- package/dist/geometry/index.js +38 -0
- package/dist/geometry/measure.d.ts +81 -0
- package/dist/geometry/measure.js +236 -0
- package/dist/geometry/predicates.d.ts +62 -0
- package/dist/geometry/predicates.js +132 -0
- package/dist/geometry/simplify.d.ts +74 -0
- package/dist/geometry/simplify.js +159 -0
- package/dist/geometry/split.d.ts +68 -0
- package/dist/geometry/split.js +430 -0
- package/dist/geometry/types.d.ts +95 -0
- package/dist/geometry/types.js +3 -0
- package/dist/geometry/units.d.ts +35 -0
- package/dist/geometry/units.js +41 -0
- package/dist/index.d.ts +72 -0
- package/dist/index.js +20 -0
- package/dist/maplibre-gl-draw.d.ts +47 -0
- package/dist/maplibre-gl-draw.js +407 -0
- package/dist/messages.d.ts +64 -0
- package/dist/messages.js +36 -0
- package/dist/modes/cursor.d.ts +1 -0
- package/dist/modes/cursor.js +72 -0
- package/dist/modes/draw/circle.d.ts +1 -0
- package/dist/modes/draw/circle.js +222 -0
- package/dist/modes/draw/commit-layer.d.ts +26 -0
- package/dist/modes/draw/commit-layer.js +31 -0
- package/dist/modes/draw/freehand.d.ts +1 -0
- package/dist/modes/draw/freehand.js +264 -0
- package/dist/modes/draw/image.d.ts +1 -0
- package/dist/modes/draw/image.js +60 -0
- package/dist/modes/draw/index.d.ts +9 -0
- package/dist/modes/draw/index.js +11 -0
- package/dist/modes/draw/line.d.ts +1 -0
- package/dist/modes/draw/line.js +363 -0
- package/dist/modes/draw/point.d.ts +1 -0
- package/dist/modes/draw/point.js +87 -0
- package/dist/modes/draw/polygon.d.ts +1 -0
- package/dist/modes/draw/polygon.js +378 -0
- package/dist/modes/draw/trace-support.d.ts +79 -0
- package/dist/modes/draw/trace-support.js +161 -0
- package/dist/modes/handler.d.ts +285 -0
- package/dist/modes/handler.js +3 -0
- package/dist/modes/index.d.ts +7 -0
- package/dist/modes/index.js +3 -0
- package/dist/modes/manager.d.ts +15 -0
- package/dist/modes/manager.js +196 -0
- package/dist/modes/select/box-selection.d.ts +52 -0
- package/dist/modes/select/box-selection.js +140 -0
- package/dist/modes/select/click-handler.d.ts +32 -0
- package/dist/modes/select/click-handler.js +166 -0
- package/dist/modes/select/cursor-handler.d.ts +15 -0
- package/dist/modes/select/cursor-handler.js +59 -0
- package/dist/modes/select/drag/auxiliary.d.ts +26 -0
- package/dist/modes/select/drag/auxiliary.js +56 -0
- package/dist/modes/select/drag/intermediate-writes.d.ts +1 -0
- package/dist/modes/select/drag/intermediate-writes.js +171 -0
- package/dist/modes/select/drag/move.d.ts +24 -0
- package/dist/modes/select/drag/move.js +59 -0
- package/dist/modes/select/drag/operation.d.ts +30 -0
- package/dist/modes/select/drag/operation.js +18 -0
- package/dist/modes/select/drag/radius.d.ts +15 -0
- package/dist/modes/select/drag/radius.js +49 -0
- package/dist/modes/select/drag/transform.d.ts +17 -0
- package/dist/modes/select/drag/transform.js +155 -0
- package/dist/modes/select/drag/vertex.d.ts +17 -0
- package/dist/modes/select/drag/vertex.js +163 -0
- package/dist/modes/select/drag-handler.d.ts +1 -0
- package/dist/modes/select/drag-handler.js +254 -0
- package/dist/modes/select/hit-helpers.d.ts +40 -0
- package/dist/modes/select/hit-helpers.js +51 -0
- package/dist/modes/select/mode.d.ts +1 -0
- package/dist/modes/select/mode.js +397 -0
- package/dist/modes/select/shortcut-handler.d.ts +40 -0
- package/dist/modes/select/shortcut-handler.js +128 -0
- package/dist/operations/index.d.ts +9 -0
- package/dist/operations/index.js +3 -0
- package/dist/operations/layer-operations.d.ts +1 -0
- package/dist/operations/layer-operations.js +350 -0
- package/dist/operations/resize.d.ts +71 -0
- package/dist/operations/resize.js +252 -0
- package/dist/operations/rotate.d.ts +17 -0
- package/dist/operations/rotate.js +166 -0
- package/dist/operations/selection-operations.d.ts +20 -0
- package/dist/operations/selection-operations.js +159 -0
- package/dist/operations/shared-vertex.d.ts +1 -0
- package/dist/operations/shared-vertex.js +210 -0
- package/dist/operations/trace-graph.d.ts +96 -0
- package/dist/operations/trace-graph.js +283 -0
- package/dist/operations/vertex.d.ts +1 -0
- package/dist/operations/vertex.js +538 -0
- package/dist/plugins/index.d.ts +10 -0
- package/dist/plugins/index.js +3 -0
- package/dist/plugins/mutation-hooks.d.ts +28 -0
- package/dist/plugins/mutation-hooks.js +84 -0
- package/dist/plugins/plugin-context.d.ts +1 -0
- package/dist/plugins/plugin-context.js +367 -0
- package/dist/plugins/plugin-manager.d.ts +103 -0
- package/dist/plugins/plugin-manager.js +316 -0
- package/dist/plugins/plugin.d.ts +529 -0
- package/dist/plugins/plugin.js +3 -0
- package/dist/shared/config/constants.d.ts +66 -0
- package/dist/shared/config/constants.js +60 -0
- package/dist/shared/config/feature-style.d.ts +155 -0
- package/dist/shared/config/feature-style.js +154 -0
- package/dist/shared/config/index.d.ts +17 -0
- package/dist/shared/config/index.js +8 -0
- package/dist/shared/config/rendering.d.ts +107 -0
- package/dist/shared/config/rendering.js +33 -0
- package/dist/shared/config/selection-highlight.d.ts +29 -0
- package/dist/shared/config/selection-highlight.js +35 -0
- package/dist/shared/config/selection.d.ts +273 -0
- package/dist/shared/config/selection.js +266 -0
- package/dist/shared/config/topology.d.ts +33 -0
- package/dist/shared/config/topology.js +17 -0
- package/dist/shared/config/trace.d.ts +40 -0
- package/dist/shared/config/trace.js +17 -0
- package/dist/shared/math/angle.d.ts +21 -0
- package/dist/shared/math/angle.js +34 -0
- package/dist/shared/math/circle.d.ts +6 -0
- package/dist/shared/math/circle.js +10 -0
- package/dist/shared/math/constants.d.ts +48 -0
- package/dist/shared/math/constants.js +59 -0
- package/dist/shared/math/distance.d.ts +78 -0
- package/dist/shared/math/distance.js +147 -0
- package/dist/shared/math/globe-subdivision.d.ts +62 -0
- package/dist/shared/math/globe-subdivision.js +99 -0
- package/dist/shared/math/index.d.ts +17 -0
- package/dist/shared/math/index.js +21 -0
- package/dist/shared/math/intersection.d.ts +63 -0
- package/dist/shared/math/intersection.js +236 -0
- package/dist/shared/math/longitude.d.ts +20 -0
- package/dist/shared/math/longitude.js +31 -0
- package/dist/shared/math/mercator-plane.d.ts +27 -0
- package/dist/shared/math/mercator-plane.js +26 -0
- package/dist/shared/math/obb.d.ts +65 -0
- package/dist/shared/math/obb.js +107 -0
- package/dist/shared/math/rotation.d.ts +93 -0
- package/dist/shared/math/rotation.js +186 -0
- package/dist/shared/math/segment-grid.d.ts +69 -0
- package/dist/shared/math/segment-grid.js +159 -0
- package/dist/shared/math/transform.d.ts +140 -0
- package/dist/shared/math/transform.js +189 -0
- package/dist/shared/types/events.d.ts +128 -0
- package/dist/shared/types/events.js +3 -0
- package/dist/shared/types/model.d.ts +950 -0
- package/dist/shared/types/model.js +3 -0
- package/dist/shared/types/selection-box.d.ts +23 -0
- package/dist/shared/types/selection-box.js +3 -0
- package/dist/shared/types/style.d.ts +68 -0
- package/dist/shared/types/style.js +3 -0
- package/dist/shared/utils/color.d.ts +49 -0
- package/dist/shared/utils/color.js +180 -0
- package/dist/shared/utils/coordinates.d.ts +52 -0
- package/dist/shared/utils/coordinates.js +75 -0
- package/dist/shared/utils/embedded-image.d.ts +34 -0
- package/dist/shared/utils/embedded-image.js +161 -0
- package/dist/shared/utils/event-emitter.d.ts +262 -0
- package/dist/shared/utils/event-emitter.js +44 -0
- package/dist/shared/utils/feature-bbox.d.ts +8 -0
- package/dist/shared/utils/feature-bbox.js +207 -0
- package/dist/shared/utils/feature-segments.d.ts +23 -0
- package/dist/shared/utils/feature-segments.js +179 -0
- package/dist/shared/utils/id.d.ts +1 -0
- package/dist/shared/utils/id.js +35 -0
- package/dist/shared/utils/image.d.ts +34 -0
- package/dist/shared/utils/image.js +106 -0
- package/dist/shared/utils/index.d.ts +15 -0
- package/dist/shared/utils/index.js +24 -0
- package/dist/shared/utils/map.d.ts +26 -0
- package/dist/shared/utils/map.js +35 -0
- package/dist/shared/utils/name-generator.d.ts +197 -0
- package/dist/shared/utils/name-generator.js +337 -0
- package/dist/shared/utils/pixel-ratio.d.ts +111 -0
- package/dist/shared/utils/pixel-ratio.js +85 -0
- package/dist/shared/utils/property.d.ts +88 -0
- package/dist/shared/utils/property.js +140 -0
- package/dist/shared/utils/vertex-ref.d.ts +23 -0
- package/dist/shared/utils/vertex-ref.js +20 -0
- package/dist/snapping/custom-targets.d.ts +1 -0
- package/dist/snapping/custom-targets.js +21 -0
- package/dist/snapping/geometry.d.ts +1 -0
- package/dist/snapping/geometry.js +61 -0
- package/dist/snapping/index.d.ts +14 -0
- package/dist/snapping/index.js +4 -0
- package/dist/snapping/indicator.d.ts +19 -0
- package/dist/snapping/indicator.js +145 -0
- package/dist/snapping/providers/display.d.ts +72 -0
- package/dist/snapping/providers/display.js +268 -0
- package/dist/snapping/providers/guide.d.ts +69 -0
- package/dist/snapping/providers/guide.js +187 -0
- package/dist/snapping/providers/intersection.d.ts +1 -0
- package/dist/snapping/providers/intersection.js +92 -0
- package/dist/snapping/providers/shared.d.ts +39 -0
- package/dist/snapping/providers/shared.js +146 -0
- package/dist/snapping/providers/store.d.ts +1 -0
- package/dist/snapping/providers/store.js +132 -0
- package/dist/snapping/service.d.ts +1 -0
- package/dist/snapping/service.js +272 -0
- package/dist/snapping/types.d.ts +267 -0
- package/dist/snapping/types.js +66 -0
- package/dist/store/change-merger.d.ts +1 -0
- package/dist/store/change-merger.js +102 -0
- package/dist/store/draw-store.d.ts +1 -0
- package/dist/store/draw-store.js +396 -0
- package/dist/store/event-bridge.d.ts +1 -0
- package/dist/store/event-bridge.js +161 -0
- package/dist/store/index.d.ts +12 -0
- package/dist/store/index.js +4 -0
- package/dist/store/local-visibility.d.ts +21 -0
- package/dist/store/local-visibility.js +27 -0
- package/dist/store/lock.d.ts +67 -0
- package/dist/store/lock.js +54 -0
- package/dist/store/memory/change-bus.d.ts +60 -0
- package/dist/store/memory/change-bus.js +232 -0
- package/dist/store/memory/file-store.d.ts +15 -0
- package/dist/store/memory/file-store.js +33 -0
- package/dist/store/memory/frozen.d.ts +21 -0
- package/dist/store/memory/frozen.js +51 -0
- package/dist/store/memory/ui-state.d.ts +51 -0
- package/dist/store/memory/ui-state.js +223 -0
- package/dist/store/memory.d.ts +26 -0
- package/dist/store/memory.js +708 -0
- package/dist/store/spatial/index.d.ts +6 -0
- package/dist/store/spatial/index.js +4 -0
- package/dist/store/spatial/spatial-index.d.ts +90 -0
- package/dist/store/spatial/spatial-index.js +148 -0
- package/dist/store/spatial/store-spatial-index.d.ts +60 -0
- package/dist/store/spatial/store-spatial-index.js +125 -0
- package/dist/store/store.d.ts +417 -0
- package/dist/store/store.js +3 -0
- package/dist/store/types.d.ts +8 -0
- package/dist/store/types.js +3 -0
- package/dist/store/writable-layer.d.ts +35 -0
- package/dist/store/writable-layer.js +20 -0
- package/dist/view/cache/buffer.d.ts +28 -0
- package/dist/view/cache/buffer.js +176 -0
- package/dist/view/cache/earcut.d.ts +1 -0
- package/dist/view/cache/earcut.js +122 -0
- package/dist/view/cache/style-rule.d.ts +1 -0
- package/dist/view/cache/style-rule.js +97 -0
- package/dist/view/cache/terrain-fill.d.ts +30 -0
- package/dist/view/cache/terrain-fill.js +60 -0
- package/dist/view/cache/texture.d.ts +14 -0
- package/dist/view/cache/texture.js +292 -0
- package/dist/view/coordinator.d.ts +27 -0
- package/dist/view/coordinator.js +72 -0
- package/dist/view/feature-companion.d.ts +173 -0
- package/dist/view/feature-companion.js +108 -0
- package/dist/view/globe-subdivision.d.ts +78 -0
- package/dist/view/globe-subdivision.js +128 -0
- package/dist/view/index.d.ts +47 -0
- package/dist/view/index.js +20 -0
- package/dist/view/layer/attach.d.ts +20 -0
- package/dist/view/layer/attach.js +47 -0
- package/dist/view/layer/blend.d.ts +57 -0
- package/dist/view/layer/blend.js +14 -0
- package/dist/view/layer/custom-layer.d.ts +1 -0
- package/dist/view/layer/custom-layer.js +509 -0
- package/dist/view/layer/depth-state.d.ts +14 -0
- package/dist/view/layer/depth-state.js +44 -0
- package/dist/view/layer/display-list.d.ts +1 -0
- package/dist/view/layer/display-list.js +111 -0
- package/dist/view/layer/drape-planner.d.ts +139 -0
- package/dist/view/layer/drape-planner.js +726 -0
- package/dist/view/layer/frame-render.d.ts +57 -0
- package/dist/view/layer/frame-render.js +209 -0
- package/dist/view/layer/frame-state.d.ts +147 -0
- package/dist/view/layer/frame-state.js +484 -0
- package/dist/view/layer/gl-state.d.ts +77 -0
- package/dist/view/layer/gl-state.js +132 -0
- package/dist/view/layer/index.d.ts +6 -0
- package/dist/view/layer/index.js +5 -0
- package/dist/view/layer/render-scope.d.ts +30 -0
- package/dist/view/layer/render-scope.js +28 -0
- package/dist/view/layer/render.d.ts +87 -0
- package/dist/view/layer/render.js +187 -0
- package/dist/view/layer/renderers.d.ts +81 -0
- package/dist/view/layer/renderers.js +142 -0
- package/dist/view/layer/slot-manager.d.ts +26 -0
- package/dist/view/layer/slot-manager.js +133 -0
- package/dist/view/layer/slots.d.ts +33 -0
- package/dist/view/layer/slots.js +50 -0
- package/dist/view/layer/store-retained-bbox.d.ts +36 -0
- package/dist/view/layer/store-retained-bbox.js +188 -0
- package/dist/view/layer/store-retained-chunk.d.ts +97 -0
- package/dist/view/layer/store-retained-chunk.js +94 -0
- package/dist/view/layer/store-retained-classify.d.ts +34 -0
- package/dist/view/layer/store-retained-classify.js +88 -0
- package/dist/view/layer/store-retained-collect.d.ts +24 -0
- package/dist/view/layer/store-retained-collect.js +121 -0
- package/dist/view/layer/store-retained-coord-patch.d.ts +119 -0
- package/dist/view/layer/store-retained-coord-patch.js +168 -0
- package/dist/view/layer/store-retained-immediate.d.ts +63 -0
- package/dist/view/layer/store-retained-immediate.js +49 -0
- package/dist/view/layer/store-retained-invalidation.d.ts +96 -0
- package/dist/view/layer/store-retained-invalidation.js +192 -0
- package/dist/view/layer/store-retained.d.ts +198 -0
- package/dist/view/layer/store-retained.js +430 -0
- package/dist/view/layer/terrain-resolver.d.ts +1 -0
- package/dist/view/layer/terrain-resolver.js +174 -0
- package/dist/view/renderers/batch-manager.d.ts +61 -0
- package/dist/view/renderers/batch-manager.js +718 -0
- package/dist/view/renderers/draw-factors.d.ts +60 -0
- package/dist/view/renderers/draw-factors.js +35 -0
- package/dist/view/renderers/drawer.d.ts +1 -0
- package/dist/view/renderers/drawer.js +346 -0
- package/dist/view/renderers/image.d.ts +1 -0
- package/dist/view/renderers/image.js +255 -0
- package/dist/view/renderers/line/dash.d.ts +31 -0
- package/dist/view/renderers/line/dash.js +152 -0
- package/dist/view/renderers/line/line-geometry.d.ts +39 -0
- package/dist/view/renderers/line/line-geometry.js +460 -0
- package/dist/view/renderers/line/line-gl.d.ts +1 -0
- package/dist/view/renderers/line/line-gl.js +236 -0
- package/dist/view/renderers/line/line-shader.d.ts +1 -0
- package/dist/view/renderers/line/line-shader.js +364 -0
- package/dist/view/renderers/line/line-types.d.ts +43 -0
- package/dist/view/renderers/line/line-types.js +3 -0
- package/dist/view/renderers/line/line-uniforms.d.ts +1 -0
- package/dist/view/renderers/line/line-uniforms.js +390 -0
- package/dist/view/renderers/line/sdf-line.d.ts +92 -0
- package/dist/view/renderers/line/sdf-line.js +567 -0
- package/dist/view/renderers/point/billboard-depth.d.ts +10 -0
- package/dist/view/renderers/point/billboard-depth.js +56 -0
- package/dist/view/renderers/point/point-instance.d.ts +124 -0
- package/dist/view/renderers/point/point-instance.js +738 -0
- package/dist/view/renderers/point/point-sdf.d.ts +58 -0
- package/dist/view/renderers/point/point-sdf.js +170 -0
- package/dist/view/renderers/point/point-shape.d.ts +99 -0
- package/dist/view/renderers/point/point-shape.js +504 -0
- package/dist/view/renderers/point/point-style.d.ts +1 -0
- package/dist/view/renderers/point/point-style.js +46 -0
- package/dist/view/renderers/polygon/batch.d.ts +26 -0
- package/dist/view/renderers/polygon/batch.js +336 -0
- package/dist/view/renderers/polygon/earcut-input.d.ts +37 -0
- package/dist/view/renderers/polygon/earcut-input.js +55 -0
- package/dist/view/renderers/polygon/earcut-sliced.d.ts +69 -0
- package/dist/view/renderers/polygon/earcut-sliced.js +960 -0
- package/dist/view/renderers/polygon/fill.d.ts +74 -0
- package/dist/view/renderers/polygon/fill.js +251 -0
- package/dist/view/renderers/polygon/sdf-polygon.d.ts +62 -0
- package/dist/view/renderers/polygon/sdf-polygon.js +919 -0
- package/dist/view/renderers/polygon/terrain-cull.d.ts +3 -0
- package/dist/view/renderers/polygon/terrain-cull.js +14 -0
- package/dist/view/renderers/polygon/triangulator.d.ts +41 -0
- package/dist/view/renderers/polygon/triangulator.js +3 -0
- package/dist/view/renderers/retained.d.ts +43 -0
- package/dist/view/renderers/retained.js +3 -0
- package/dist/view/renderers/stroke.d.ts +121 -0
- package/dist/view/renderers/stroke.js +621 -0
- package/dist/view/shaders/frame.d.ts +8 -0
- package/dist/view/shaders/frame.js +37 -0
- package/dist/view/shaders/helpers.d.ts +238 -0
- package/dist/view/shaders/helpers.js +611 -0
- package/dist/view/shaders/initializer.d.ts +27 -0
- package/dist/view/shaders/initializer.js +125 -0
- package/dist/view/shaders/projection.d.ts +123 -0
- package/dist/view/shaders/projection.js +299 -0
- package/dist/view/shaders/quad-grid.d.ts +77 -0
- package/dist/view/shaders/quad-grid.js +128 -0
- package/dist/view/shaders/quad.d.ts +189 -0
- package/dist/view/shaders/quad.js +582 -0
- package/dist/view/shaders/retained-origin.d.ts +50 -0
- package/dist/view/shaders/retained-origin.js +67 -0
- package/dist/view/shaders/terrain-shade.d.ts +23 -0
- package/dist/view/shaders/terrain-shade.js +93 -0
- package/dist/view/style-rule.d.ts +166 -0
- package/dist/view/style-rule.js +300 -0
- package/dist/view/terrain/anchor.d.ts +135 -0
- package/dist/view/terrain/anchor.js +226 -0
- package/dist/view/terrain/context.d.ts +132 -0
- package/dist/view/terrain/context.js +437 -0
- package/dist/view/terrain/dem-atlas.d.ts +97 -0
- package/dist/view/terrain/dem-atlas.js +534 -0
- package/dist/view/terrain/detect.d.ts +126 -0
- package/dist/view/terrain/detect.js +198 -0
- package/dist/view/terrain/drape/bin-store.d.ts +179 -0
- package/dist/view/terrain/drape/bin-store.js +529 -0
- package/dist/view/terrain/drape/binning.d.ts +259 -0
- package/dist/view/terrain/drape/binning.js +604 -0
- package/dist/view/terrain/drape/edge-constrain.d.ts +37 -0
- package/dist/view/terrain/drape/edge-constrain.js +175 -0
- package/dist/view/terrain/drape/geometry.d.ts +95 -0
- package/dist/view/terrain/drape/geometry.js +260 -0
- package/dist/view/terrain/drape/mesh.d.ts +50 -0
- package/dist/view/terrain/drape/mesh.js +86 -0
- package/dist/view/terrain/drape/pass.d.ts +122 -0
- package/dist/view/terrain/drape/pass.js +379 -0
- package/dist/view/terrain/drape/quad-glyphs.d.ts +64 -0
- package/dist/view/terrain/drape/quad-glyphs.js +117 -0
- package/dist/view/terrain/drape/quad.d.ts +249 -0
- package/dist/view/terrain/drape/quad.js +835 -0
- package/dist/view/terrain/drape/renderer.d.ts +184 -0
- package/dist/view/terrain/drape/renderer.js +706 -0
- package/dist/view/terrain/drape/shared.d.ts +80 -0
- package/dist/view/terrain/drape/shared.js +173 -0
- package/dist/view/terrain/drape/stitch.d.ts +155 -0
- package/dist/view/terrain/drape/stitch.js +228 -0
- package/dist/view/terrain/ground.d.ts +72 -0
- package/dist/view/terrain/ground.js +151 -0
- package/dist/view/terrain/metrics.d.ts +180 -0
- package/dist/view/terrain/metrics.js +231 -0
- package/dist/view/terrain/occlusion.d.ts +11 -0
- package/dist/view/terrain/occlusion.js +129 -0
- package/dist/view/terrain/polygon.d.ts +86 -0
- package/dist/view/terrain/polygon.js +301 -0
- package/dist/view/terrain/shade.d.ts +48 -0
- package/dist/view/terrain/shade.js +45 -0
- package/dist/view/terrain/state.d.ts +99 -0
- package/dist/view/terrain/state.js +186 -0
- package/dist/view/terrain/tessellation.d.ts +265 -0
- package/dist/view/terrain/tessellation.js +924 -0
- package/dist/view/terrain/tiling.d.ts +56 -0
- package/dist/view/terrain/tiling.js +155 -0
- package/dist/view/terrain/upstream-terrain.d.ts +82 -0
- package/dist/view/terrain/upstream-terrain.js +116 -0
- package/dist/view/ui/auxiliary-handles.d.ts +151 -0
- package/dist/view/ui/auxiliary-handles.js +22 -0
- package/dist/view/ui/bounds.d.ts +53 -0
- package/dist/view/ui/bounds.js +149 -0
- package/dist/view/ui/box-selection.d.ts +1 -0
- package/dist/view/ui/box-selection.js +83 -0
- package/dist/view/ui/handle-test.d.ts +1 -0
- package/dist/view/ui/handle-test.js +437 -0
- package/dist/view/ui/handle-thinning.d.ts +122 -0
- package/dist/view/ui/handle-thinning.js +430 -0
- package/dist/view/ui/handles.d.ts +25 -0
- package/dist/view/ui/handles.js +673 -0
- package/dist/view/ui/helper.d.ts +19 -0
- package/dist/view/ui/helper.js +76 -0
- package/dist/view/ui/index.d.ts +15 -0
- package/dist/view/ui/index.js +15 -0
- package/dist/view/ui/selection-scope.d.ts +25 -0
- package/dist/view/ui/selection-scope.js +34 -0
- package/dist/view/ui/selection-ui/bounding-box.d.ts +44 -0
- package/dist/view/ui/selection-ui/bounding-box.js +240 -0
- package/dist/view/ui/selection-ui/extension-registry.d.ts +76 -0
- package/dist/view/ui/selection-ui/extension-registry.js +78 -0
- package/dist/view/ui/selection-ui/index.d.ts +12 -0
- package/dist/view/ui/selection-ui/index.js +12 -0
- package/dist/view/ui/selection-ui/renderer.d.ts +29 -0
- package/dist/view/ui/selection-ui/renderer.js +227 -0
- package/dist/view/ui/selection-ui/types.d.ts +55 -0
- package/dist/view/ui/selection-ui/types.js +3 -0
- package/dist/view/ui/selection-ui-drawer.d.ts +52 -0
- package/dist/view/ui/selection-ui-drawer.js +329 -0
- package/dist/view/ui/tentative.d.ts +1 -0
- package/dist/view/ui/tentative.js +320 -0
- package/dist/view/viewport.d.ts +119 -0
- package/dist/view/viewport.js +254 -0
- package/package.json +113 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The corners of a selection box
|
|
3
|
+
*/
|
|
4
|
+
import type { Coordinate } from './model.js';
|
|
5
|
+
/**
|
|
6
|
+
* The four corners and the center of a selection box, as geographic coordinates
|
|
7
|
+
*
|
|
8
|
+
* The box may be rotated with its feature (an Image, or a custom type that returns an
|
|
9
|
+
* oriented box), so the corners are named in the box's own orientation: `topLeft` is the
|
|
10
|
+
* top-left corner before the rotation.
|
|
11
|
+
*/
|
|
12
|
+
export interface BoundingBoxCoords {
|
|
13
|
+
/** The top-left corner */
|
|
14
|
+
topLeft: Coordinate;
|
|
15
|
+
/** The top-right corner */
|
|
16
|
+
topRight: Coordinate;
|
|
17
|
+
/** The bottom-right corner */
|
|
18
|
+
bottomRight: Coordinate;
|
|
19
|
+
/** The bottom-left corner */
|
|
20
|
+
bottomLeft: Coordinate;
|
|
21
|
+
/** The center */
|
|
22
|
+
center: Coordinate;
|
|
23
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The style types shared by the configuration (shared/config) and the renderers (view/)
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* An RGBA color as four numbers from 0 to 1: `[red, green, blue, alpha]`
|
|
6
|
+
*
|
|
7
|
+
* The configuration of the renderers uses it; the style of a feature ({@link FeatureStyle})
|
|
8
|
+
* uses `#rrggbb` strings instead. `#FF2D55` is `[1.0, 0.176, 0.333, 1.0]`.
|
|
9
|
+
*/
|
|
10
|
+
export type Color = [number, number, number, number];
|
|
11
|
+
/**
|
|
12
|
+
* The shape of a point marker or a handle
|
|
13
|
+
*
|
|
14
|
+
* The built-in renderers draw `'circle'`, `'square'`, `'triangle'` (equilateral, a vertex
|
|
15
|
+
* pointing up) and `'star'` (a five-pointed star, a tip pointing up). The triangle and the star
|
|
16
|
+
* are inscribed in the circle the `'circle'` shape of the same style draws (the size plus the
|
|
17
|
+
* stroke), and their stroke is drawn inside that outline. `'icon'` is a name for an extension
|
|
18
|
+
* renderer to draw (with `iconId` of {@link PointStyle}); the built-in renderers draw it as a
|
|
19
|
+
* circle.
|
|
20
|
+
*
|
|
21
|
+
* Hit testing does not look at the shape: a triangle or a star is hit like the circle that
|
|
22
|
+
* encloses it.
|
|
23
|
+
*/
|
|
24
|
+
export type PointShape = 'circle' | 'square' | 'triangle' | 'star' | 'icon';
|
|
25
|
+
/**
|
|
26
|
+
* How a point marker or a handle is drawn: its shape, size, fill and outline
|
|
27
|
+
*/
|
|
28
|
+
export interface PointStyle {
|
|
29
|
+
/** The shape */
|
|
30
|
+
shape: PointShape;
|
|
31
|
+
/**
|
|
32
|
+
* The size in CSS pixels (the diameter of a circle, the side of a square; a triangle and a star
|
|
33
|
+
* are inscribed in the circle of this size plus the stroke)
|
|
34
|
+
*/
|
|
35
|
+
size: number;
|
|
36
|
+
/** The fill color */
|
|
37
|
+
fillColor: Color;
|
|
38
|
+
/** The opacity of the fill, from 0 to 1 (multiplied into the alpha of `fillColor`) */
|
|
39
|
+
fillOpacity: number;
|
|
40
|
+
/** The color of the outline */
|
|
41
|
+
strokeColor: Color;
|
|
42
|
+
/** The width of the outline in CSS pixels (0 for no outline) */
|
|
43
|
+
strokeWidth: number;
|
|
44
|
+
/** The opacity of the outline, from 0 to 1 */
|
|
45
|
+
strokeOpacity: number;
|
|
46
|
+
/** The identifier of the icon, for the `'icon'` shape */
|
|
47
|
+
iconId?: string;
|
|
48
|
+
}
|
|
49
|
+
/** The dash pattern of a line: solid, dashed or dotted */
|
|
50
|
+
export type LineStyle = 'solid' | 'dashed' | 'dotted';
|
|
51
|
+
/**
|
|
52
|
+
* How a line or an outline is drawn: its width, color, opacity and dash pattern
|
|
53
|
+
*/
|
|
54
|
+
export interface StrokeStyle {
|
|
55
|
+
/** The width in CSS pixels */
|
|
56
|
+
width: number;
|
|
57
|
+
/** The color */
|
|
58
|
+
color: Color;
|
|
59
|
+
/** The opacity from 0 to 1 (multiplied into the alpha of `color`) */
|
|
60
|
+
opacity: number;
|
|
61
|
+
/** The dash pattern */
|
|
62
|
+
lineStyle: LineStyle;
|
|
63
|
+
/**
|
|
64
|
+
* A custom dash pattern in CSS pixels, `[dash, gap]`, used instead of the pattern of
|
|
65
|
+
* `lineStyle` when `lineStyle` is not `'solid'`
|
|
66
|
+
*/
|
|
67
|
+
dashArray?: number[];
|
|
68
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Color conversion utilities
|
|
3
|
+
*
|
|
4
|
+
* Functions that convert between HEX color strings and RGBA arrays.
|
|
5
|
+
*/
|
|
6
|
+
import type { Color } from '../types/style.js';
|
|
7
|
+
/**
|
|
8
|
+
* Converts a HEX color string into an RGBA array
|
|
9
|
+
*
|
|
10
|
+
* @param hex - A color string in #RRGGBB or #RGB form
|
|
11
|
+
* @param opacity - Opacity (0-1)
|
|
12
|
+
* @returns An array in the form [r, g, b, a] (each value in 0-1)
|
|
13
|
+
*/
|
|
14
|
+
export declare function hexToColor(hex: string, opacity?: number): Color;
|
|
15
|
+
/**
|
|
16
|
+
* Linearly interpolates two colors in the OKLab space
|
|
17
|
+
*
|
|
18
|
+
* Used for continuous color ramps (continuous in the style rules).
|
|
19
|
+
* Interpolation in the RGB space skews the brightness unevenly and, depending on the hue,
|
|
20
|
+
* muddies the middle, so the perceptually uniform L, a and b of OKLab are interpolated
|
|
21
|
+
* component by component.
|
|
22
|
+
* The interpolation position is clamped to 0-1.
|
|
23
|
+
*
|
|
24
|
+
* @param from - Color of the start point (#RRGGBB or #RGB)
|
|
25
|
+
* @param to - Color of the end point (#RRGGBB or #RGB)
|
|
26
|
+
* @param t - Interpolation position (0-1)
|
|
27
|
+
* @returns A color string in #RRGGBB form
|
|
28
|
+
*/
|
|
29
|
+
export declare function interpolateHexColor(from: string, to: string, t: number): string;
|
|
30
|
+
/**
|
|
31
|
+
* Computes the relative luminance
|
|
32
|
+
*
|
|
33
|
+
* Based on the relative luminance formula of WCAG 2.0.
|
|
34
|
+
* https://www.w3.org/TR/WCAG20/#relativeluminancedef
|
|
35
|
+
*
|
|
36
|
+
* @param hex - A color string in #RRGGBB or #RGB form
|
|
37
|
+
* @returns Relative luminance (0-1)
|
|
38
|
+
*/
|
|
39
|
+
export declare function getLuminance(hex: string): number;
|
|
40
|
+
/**
|
|
41
|
+
* Gets a contrasting color
|
|
42
|
+
*
|
|
43
|
+
* Returns a highly visible contrasting color based on the luminance of the given color.
|
|
44
|
+
* Returns black for a light color and white for a dark color.
|
|
45
|
+
*
|
|
46
|
+
* @param hex - A color string in #RRGGBB or #RGB form
|
|
47
|
+
* @returns The contrasting color (#000000 or #FFFFFF)
|
|
48
|
+
*/
|
|
49
|
+
export declare function getContrastColor(hex: string): string;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 SAKAIDA Atsushi
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
/**
|
|
4
|
+
* Extracts the RGB values from a HEX color string
|
|
5
|
+
*
|
|
6
|
+
* @param hex - A color string in #RRGGBB or #RGB form
|
|
7
|
+
* @returns { r, g, b }, each value in 0-255
|
|
8
|
+
*/
|
|
9
|
+
function parseHexToRgb(hex) {
|
|
10
|
+
const cleanHex = hex.replace('#', '');
|
|
11
|
+
let r;
|
|
12
|
+
let g;
|
|
13
|
+
let b;
|
|
14
|
+
if (cleanHex.length === 3) {
|
|
15
|
+
// #RGB form
|
|
16
|
+
r = Number.parseInt(cleanHex[0] + cleanHex[0], 16);
|
|
17
|
+
g = Number.parseInt(cleanHex[1] + cleanHex[1], 16);
|
|
18
|
+
b = Number.parseInt(cleanHex[2] + cleanHex[2], 16);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
// #RRGGBB form
|
|
22
|
+
r = Number.parseInt(cleanHex.substring(0, 2), 16);
|
|
23
|
+
g = Number.parseInt(cleanHex.substring(2, 4), 16);
|
|
24
|
+
b = Number.parseInt(cleanHex.substring(4, 6), 16);
|
|
25
|
+
}
|
|
26
|
+
return { r, g, b };
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Converts a HEX color string into an RGBA array
|
|
30
|
+
*
|
|
31
|
+
* @param hex - A color string in #RRGGBB or #RGB form
|
|
32
|
+
* @param opacity - Opacity (0-1)
|
|
33
|
+
* @returns An array in the form [r, g, b, a] (each value in 0-1)
|
|
34
|
+
*/
|
|
35
|
+
export function hexToColor(hex, opacity = 1) {
|
|
36
|
+
const { r, g, b } = parseHexToRgb(hex);
|
|
37
|
+
return [r / 255, g / 255, b / 255, opacity];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Converts RGB values into a HEX color string
|
|
41
|
+
*
|
|
42
|
+
* @param r - Red (0-255)
|
|
43
|
+
* @param g - Green (0-255)
|
|
44
|
+
* @param b - Blue (0-255)
|
|
45
|
+
* @returns A color string in #RRGGBB form
|
|
46
|
+
*/
|
|
47
|
+
function rgbToHex(r, g, b) {
|
|
48
|
+
const toHex = (c) => Math.max(0, Math.min(255, Math.round(c)))
|
|
49
|
+
.toString(16)
|
|
50
|
+
.padStart(2, '0');
|
|
51
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Converts sRGB (0-255) into linear sRGB (0-1)
|
|
55
|
+
*
|
|
56
|
+
* Uses the piecewise formula of IEC 61966-2-1 (threshold 0.04045).
|
|
57
|
+
*
|
|
58
|
+
* @param c - sRGB component (0-255)
|
|
59
|
+
* @returns Linear sRGB component (0-1)
|
|
60
|
+
*/
|
|
61
|
+
function srgbToLinear(c) {
|
|
62
|
+
const srgb = c / 255;
|
|
63
|
+
return srgb <= 0.04045 ? srgb / 12.92 : ((srgb + 0.055) / 1.055) ** 2.4;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Converts linear sRGB (0-1) into sRGB (0-255)
|
|
67
|
+
*
|
|
68
|
+
* Components that fall outside 0-1 in the inverse conversion are clamped here.
|
|
69
|
+
*
|
|
70
|
+
* @param c - Linear sRGB component
|
|
71
|
+
* @returns sRGB component (0-255)
|
|
72
|
+
*/
|
|
73
|
+
function linearToSrgb(c) {
|
|
74
|
+
const linear = Math.min(1, Math.max(0, c));
|
|
75
|
+
const srgb = linear <= 0.0031308 ? linear * 12.92 : 1.055 * linear ** (1 / 2.4) - 0.055;
|
|
76
|
+
return srgb * 255;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Converts a HEX color string into OKLab
|
|
80
|
+
*
|
|
81
|
+
* Uses the coefficients from Björn Ottosson's original article
|
|
82
|
+
* (https://bottosson.github.io/posts/oklab/). It maps in the order sRGB -> linear sRGB -> LMS
|
|
83
|
+
* -> cube root -> OKLab.
|
|
84
|
+
*
|
|
85
|
+
* @param hex - A color string in #RRGGBB or #RGB form
|
|
86
|
+
* @returns { L, a, b } OKLab coordinates
|
|
87
|
+
*/
|
|
88
|
+
function hexToOklab(hex) {
|
|
89
|
+
const rgb = parseHexToRgb(hex);
|
|
90
|
+
const r = srgbToLinear(rgb.r);
|
|
91
|
+
const g = srgbToLinear(rgb.g);
|
|
92
|
+
const b = srgbToLinear(rgb.b);
|
|
93
|
+
const l = 0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b;
|
|
94
|
+
const m = 0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b;
|
|
95
|
+
const s = 0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b;
|
|
96
|
+
const l_ = Math.cbrt(l);
|
|
97
|
+
const m_ = Math.cbrt(m);
|
|
98
|
+
const s_ = Math.cbrt(s);
|
|
99
|
+
return {
|
|
100
|
+
L: 0.2104542553 * l_ + 0.793617785 * m_ - 0.0040720468 * s_,
|
|
101
|
+
a: 1.9779984951 * l_ - 2.428592205 * m_ + 0.4505937099 * s_,
|
|
102
|
+
b: 0.0259040371 * l_ + 0.7827717662 * m_ - 0.808675766 * s_,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Converts OKLab into a HEX color string
|
|
107
|
+
*
|
|
108
|
+
* The inverse of hexToOklab. Out-of-gamut components are clamped at the linear sRGB stage.
|
|
109
|
+
*
|
|
110
|
+
* @param L - Lightness
|
|
111
|
+
* @param a - The green-to-red axis
|
|
112
|
+
* @param b - The blue-to-yellow axis
|
|
113
|
+
* @returns A color string in #rrggbb form
|
|
114
|
+
*/
|
|
115
|
+
function oklabToHex(L, a, b) {
|
|
116
|
+
const l_ = L + 0.3963377774 * a + 0.2158037573 * b;
|
|
117
|
+
const m_ = L - 0.1055613458 * a - 0.0638541728 * b;
|
|
118
|
+
const s_ = L - 0.0894841775 * a - 1.291485548 * b;
|
|
119
|
+
const l = l_ * l_ * l_;
|
|
120
|
+
const m = m_ * m_ * m_;
|
|
121
|
+
const s = s_ * s_ * s_;
|
|
122
|
+
return rgbToHex(linearToSrgb(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s), linearToSrgb(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s), linearToSrgb(-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s));
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Linearly interpolates two colors in the OKLab space
|
|
126
|
+
*
|
|
127
|
+
* Used for continuous color ramps (continuous in the style rules).
|
|
128
|
+
* Interpolation in the RGB space skews the brightness unevenly and, depending on the hue,
|
|
129
|
+
* muddies the middle, so the perceptually uniform L, a and b of OKLab are interpolated
|
|
130
|
+
* component by component.
|
|
131
|
+
* The interpolation position is clamped to 0-1.
|
|
132
|
+
*
|
|
133
|
+
* @param from - Color of the start point (#RRGGBB or #RGB)
|
|
134
|
+
* @param to - Color of the end point (#RRGGBB or #RGB)
|
|
135
|
+
* @param t - Interpolation position (0-1)
|
|
136
|
+
* @returns A color string in #RRGGBB form
|
|
137
|
+
*/
|
|
138
|
+
export function interpolateHexColor(from, to, t) {
|
|
139
|
+
const ratio = Math.min(1, Math.max(0, t));
|
|
140
|
+
const a = hexToOklab(from);
|
|
141
|
+
const b = hexToOklab(to);
|
|
142
|
+
return oklabToHex(a.L + (b.L - a.L) * ratio, a.a + (b.a - a.a) * ratio, a.b + (b.b - a.b) * ratio);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Computes the relative luminance
|
|
146
|
+
*
|
|
147
|
+
* Based on the relative luminance formula of WCAG 2.0.
|
|
148
|
+
* https://www.w3.org/TR/WCAG20/#relativeluminancedef
|
|
149
|
+
*
|
|
150
|
+
* @param hex - A color string in #RRGGBB or #RGB form
|
|
151
|
+
* @returns Relative luminance (0-1)
|
|
152
|
+
*/
|
|
153
|
+
export function getLuminance(hex) {
|
|
154
|
+
const { r, g, b } = parseHexToRgb(hex);
|
|
155
|
+
// Convert from sRGB into a linear value
|
|
156
|
+
const toLinear = (c) => {
|
|
157
|
+
const srgb = c / 255;
|
|
158
|
+
return srgb <= 0.03928 ? srgb / 12.92 : ((srgb + 0.055) / 1.055) ** 2.4;
|
|
159
|
+
};
|
|
160
|
+
const rLinear = toLinear(r);
|
|
161
|
+
const gLinear = toLinear(g);
|
|
162
|
+
const bLinear = toLinear(b);
|
|
163
|
+
// Computation of the relative luminance
|
|
164
|
+
return 0.2126 * rLinear + 0.7152 * gLinear + 0.0722 * bLinear;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Gets a contrasting color
|
|
168
|
+
*
|
|
169
|
+
* Returns a highly visible contrasting color based on the luminance of the given color.
|
|
170
|
+
* Returns black for a light color and white for a dark color.
|
|
171
|
+
*
|
|
172
|
+
* @param hex - A color string in #RRGGBB or #RGB form
|
|
173
|
+
* @returns The contrasting color (#000000 or #FFFFFF)
|
|
174
|
+
*/
|
|
175
|
+
export function getContrastColor(hex) {
|
|
176
|
+
const luminance = getLuminance(hex);
|
|
177
|
+
// A luminance above 0.5 means a light color -> a black outline
|
|
178
|
+
// A luminance at or below 0.5 means a dark color -> a white outline
|
|
179
|
+
return luminance > 0.5 ? '#000000' : '#FFFFFF';
|
|
180
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coordinate traversal utilities
|
|
3
|
+
*
|
|
4
|
+
* The coordinates of a Feature have a different array nesting depth per type
|
|
5
|
+
* (Point has 1 level, LineString has 2, Polygon / MultiLineString have 3, and
|
|
6
|
+
* MultiPolygon has 4). Moving, resizing, rotating and computing the bounding box apply the
|
|
7
|
+
* same processing to every coordinate at any depth, so the depth-independent recursive
|
|
8
|
+
* traversal is collected here.
|
|
9
|
+
*/
|
|
10
|
+
import type { Coordinate, FeatureCoordinates, FeatureType } from '../types/model.js';
|
|
11
|
+
/**
|
|
12
|
+
* The Multi family of feature types
|
|
13
|
+
*/
|
|
14
|
+
export declare const MULTI_FEATURE_TYPES: readonly ["MultiPoint", "MultiLineString", "MultiPolygon"];
|
|
15
|
+
/**
|
|
16
|
+
* Tests whether it is one of the Multi family of feature types
|
|
17
|
+
*/
|
|
18
|
+
export declare function isMultiFeatureType(type: FeatureType): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Tests whether a value is a single coordinate `[lng, lat]`
|
|
21
|
+
*/
|
|
22
|
+
export declare function isCoordinate(value: unknown): value is Coordinate;
|
|
23
|
+
/**
|
|
24
|
+
* Returns new coordinates with a transform function applied to every coordinate (the nesting
|
|
25
|
+
* depth is preserved)
|
|
26
|
+
*
|
|
27
|
+
* The coordinate mapping of moving, resizing and rotating shares this function.
|
|
28
|
+
* It can traverse the 4-level nesting of a Multi geometry as is.
|
|
29
|
+
*/
|
|
30
|
+
export declare function mapCoordinatesDeep<T extends FeatureCoordinates>(coords: T, transform: (coord: Coordinate) => Coordinate): T;
|
|
31
|
+
/**
|
|
32
|
+
* Enumerates every coordinate in order
|
|
33
|
+
*
|
|
34
|
+
* Used in the union computation of the bounding box and of hit testing.
|
|
35
|
+
*/
|
|
36
|
+
export declare function forEachCoordinateDeep(coords: FeatureCoordinates, visit: (coord: Coordinate) => void): void;
|
|
37
|
+
/**
|
|
38
|
+
* Gets every coordinate as a flat array
|
|
39
|
+
*/
|
|
40
|
+
export declare function flattenCoordinatesDeep(coords: FeatureCoordinates): Coordinate[];
|
|
41
|
+
/**
|
|
42
|
+
* Whether the feature type supports vertex editing (vertex handles / midpoint handles)
|
|
43
|
+
*
|
|
44
|
+
* LineString / Polygon and the Multi types are supported. Point / Circle / Freehand /
|
|
45
|
+
* Image / custom features do not show vertex handles; they are edited with move, resize
|
|
46
|
+
* and rotate only.
|
|
47
|
+
*
|
|
48
|
+
* Handle rendering, hit testing, click-based vertex selection and the visibility control
|
|
49
|
+
* of the selection UI all share this predicate, which prevents per-path discrepancies
|
|
50
|
+
* such as "visible but not grabbable" or "grabbable but not selectable".
|
|
51
|
+
*/
|
|
52
|
+
export declare function supportsVertexEditing(type: FeatureType): boolean;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 SAKAIDA Atsushi
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
/**
|
|
4
|
+
* The Multi family of feature types
|
|
5
|
+
*/
|
|
6
|
+
export const MULTI_FEATURE_TYPES = ['MultiPoint', 'MultiLineString', 'MultiPolygon'];
|
|
7
|
+
const MULTI_FEATURE_TYPE_SET = new Set(MULTI_FEATURE_TYPES);
|
|
8
|
+
/**
|
|
9
|
+
* Tests whether it is one of the Multi family of feature types
|
|
10
|
+
*/
|
|
11
|
+
export function isMultiFeatureType(type) {
|
|
12
|
+
return MULTI_FEATURE_TYPE_SET.has(type);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Tests whether a value is a single coordinate `[lng, lat]`
|
|
16
|
+
*/
|
|
17
|
+
export function isCoordinate(value) {
|
|
18
|
+
return Array.isArray(value) && value.length === 2 && typeof value[0] === 'number';
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Returns new coordinates with a transform function applied to every coordinate (the nesting
|
|
22
|
+
* depth is preserved)
|
|
23
|
+
*
|
|
24
|
+
* The coordinate mapping of moving, resizing and rotating shares this function.
|
|
25
|
+
* It can traverse the 4-level nesting of a Multi geometry as is.
|
|
26
|
+
*/
|
|
27
|
+
export function mapCoordinatesDeep(coords, transform) {
|
|
28
|
+
if (isCoordinate(coords)) {
|
|
29
|
+
return transform(coords);
|
|
30
|
+
}
|
|
31
|
+
if (Array.isArray(coords)) {
|
|
32
|
+
return coords.map((child) => mapCoordinatesDeep(child, transform));
|
|
33
|
+
}
|
|
34
|
+
return coords;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Enumerates every coordinate in order
|
|
38
|
+
*
|
|
39
|
+
* Used in the union computation of the bounding box and of hit testing.
|
|
40
|
+
*/
|
|
41
|
+
export function forEachCoordinateDeep(coords, visit) {
|
|
42
|
+
if (isCoordinate(coords)) {
|
|
43
|
+
visit(coords);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray(coords)) {
|
|
47
|
+
for (const child of coords) {
|
|
48
|
+
forEachCoordinateDeep(child, visit);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Gets every coordinate as a flat array
|
|
54
|
+
*/
|
|
55
|
+
export function flattenCoordinatesDeep(coords) {
|
|
56
|
+
const result = [];
|
|
57
|
+
forEachCoordinateDeep(coords, (coord) => {
|
|
58
|
+
result.push(coord);
|
|
59
|
+
});
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Whether the feature type supports vertex editing (vertex handles / midpoint handles)
|
|
64
|
+
*
|
|
65
|
+
* LineString / Polygon and the Multi types are supported. Point / Circle / Freehand /
|
|
66
|
+
* Image / custom features do not show vertex handles; they are edited with move, resize
|
|
67
|
+
* and rotate only.
|
|
68
|
+
*
|
|
69
|
+
* Handle rendering, hit testing, click-based vertex selection and the visibility control
|
|
70
|
+
* of the selection UI all share this predicate, which prevents per-path discrepancies
|
|
71
|
+
* such as "visible but not grabbable" or "grabbable but not selectable".
|
|
72
|
+
*/
|
|
73
|
+
export function supportsVertexEditing(type) {
|
|
74
|
+
return type === 'LineString' || type === 'Polygon' || isMultiFeatureType(type);
|
|
75
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Embedded image data URLs
|
|
3
|
+
*
|
|
4
|
+
* Image features reference their pixels through a data URL held in FileData. Such a URL is
|
|
5
|
+
* handed to `new Image().src`, so anything other than an embedded raster image (an http(s)
|
|
6
|
+
* URL, a blob URL, SVG and so on) would make every viewer of the data send a request to an
|
|
7
|
+
* outside host or run a decoder the library does not expect. The only accepted form is
|
|
8
|
+
* `data:image/(png|jpeg|webp|gif);base64,…`, and the pixel size is read from the header of the
|
|
9
|
+
* decoded bytes so that an oversized image can be scaled down before it reaches the GPU.
|
|
10
|
+
*/
|
|
11
|
+
/** The MIME types accepted for embedded images */
|
|
12
|
+
export declare const EMBEDDED_IMAGE_MIME_TYPES: readonly ["image/png", "image/jpeg", "image/webp", "image/gif"];
|
|
13
|
+
export type EmbeddedImageMimeType = (typeof EMBEDDED_IMAGE_MIME_TYPES)[number];
|
|
14
|
+
/** The facts read from an embedded image */
|
|
15
|
+
export interface EmbeddedImageInfo {
|
|
16
|
+
/** The MIME type found in the bytes (it matches the one in the data URL) */
|
|
17
|
+
mimeType: EmbeddedImageMimeType;
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Whether the value has the form of an embedded raster image data URL
|
|
23
|
+
*
|
|
24
|
+
* Only the prefix and the Base64 alphabet are checked; the bytes are not decoded. Used at the
|
|
25
|
+
* rendering boundary, where the value has already been validated on import.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isEmbeddedImageDataUrl(value: unknown): value is string;
|
|
28
|
+
/**
|
|
29
|
+
* Reads the MIME type and the pixel size of an embedded image data URL
|
|
30
|
+
*
|
|
31
|
+
* @returns null when the value is not an accepted data URL, when the bytes are not an image
|
|
32
|
+
* of the declared type, or when the size cannot be read
|
|
33
|
+
*/
|
|
34
|
+
export declare function readEmbeddedImage(value: unknown): EmbeddedImageInfo | null;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 SAKAIDA Atsushi
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
/**
|
|
4
|
+
* Embedded image data URLs
|
|
5
|
+
*
|
|
6
|
+
* Image features reference their pixels through a data URL held in FileData. Such a URL is
|
|
7
|
+
* handed to `new Image().src`, so anything other than an embedded raster image (an http(s)
|
|
8
|
+
* URL, a blob URL, SVG and so on) would make every viewer of the data send a request to an
|
|
9
|
+
* outside host or run a decoder the library does not expect. The only accepted form is
|
|
10
|
+
* `data:image/(png|jpeg|webp|gif);base64,…`, and the pixel size is read from the header of the
|
|
11
|
+
* decoded bytes so that an oversized image can be scaled down before it reaches the GPU.
|
|
12
|
+
*/
|
|
13
|
+
/** The MIME types accepted for embedded images */
|
|
14
|
+
export const EMBEDDED_IMAGE_MIME_TYPES = [
|
|
15
|
+
'image/png',
|
|
16
|
+
'image/jpeg',
|
|
17
|
+
'image/webp',
|
|
18
|
+
'image/gif',
|
|
19
|
+
];
|
|
20
|
+
const EMBEDDED_IMAGE_PREFIX = /^data:(image\/(?:png|jpeg|webp|gif));base64,/;
|
|
21
|
+
const BASE64_BODY = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
22
|
+
/**
|
|
23
|
+
* Whether the value has the form of an embedded raster image data URL
|
|
24
|
+
*
|
|
25
|
+
* Only the prefix and the Base64 alphabet are checked; the bytes are not decoded. Used at the
|
|
26
|
+
* rendering boundary, where the value has already been validated on import.
|
|
27
|
+
*/
|
|
28
|
+
export function isEmbeddedImageDataUrl(value) {
|
|
29
|
+
if (typeof value !== 'string')
|
|
30
|
+
return false;
|
|
31
|
+
const match = EMBEDDED_IMAGE_PREFIX.exec(value);
|
|
32
|
+
if (!match)
|
|
33
|
+
return false;
|
|
34
|
+
return BASE64_BODY.test(value.slice(match[0].length));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Reads the MIME type and the pixel size of an embedded image data URL
|
|
38
|
+
*
|
|
39
|
+
* @returns null when the value is not an accepted data URL, when the bytes are not an image
|
|
40
|
+
* of the declared type, or when the size cannot be read
|
|
41
|
+
*/
|
|
42
|
+
export function readEmbeddedImage(value) {
|
|
43
|
+
if (!isEmbeddedImageDataUrl(value))
|
|
44
|
+
return null;
|
|
45
|
+
const match = EMBEDDED_IMAGE_PREFIX.exec(value);
|
|
46
|
+
if (!match)
|
|
47
|
+
return null;
|
|
48
|
+
const declared = match[1];
|
|
49
|
+
let bytes;
|
|
50
|
+
try {
|
|
51
|
+
bytes = atob(value.slice(match[0].length));
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const info = readImageHeader(bytes);
|
|
57
|
+
if (!info || info.mimeType !== declared)
|
|
58
|
+
return null;
|
|
59
|
+
if (!(info.width > 0 && info.height > 0))
|
|
60
|
+
return null;
|
|
61
|
+
return info;
|
|
62
|
+
}
|
|
63
|
+
// ============================================================================
|
|
64
|
+
// Header parsing (bytes are a binary string, one char per byte)
|
|
65
|
+
// ============================================================================
|
|
66
|
+
function u8(b, i) {
|
|
67
|
+
return b.charCodeAt(i) & 0xff;
|
|
68
|
+
}
|
|
69
|
+
function u16be(b, i) {
|
|
70
|
+
return (u8(b, i) << 8) | u8(b, i + 1);
|
|
71
|
+
}
|
|
72
|
+
function u16le(b, i) {
|
|
73
|
+
return u8(b, i) | (u8(b, i + 1) << 8);
|
|
74
|
+
}
|
|
75
|
+
function u24le(b, i) {
|
|
76
|
+
return u8(b, i) | (u8(b, i + 1) << 8) | (u8(b, i + 2) << 16);
|
|
77
|
+
}
|
|
78
|
+
function u32be(b, i) {
|
|
79
|
+
return ((u8(b, i) << 24) >>> 0) + (u8(b, i + 1) << 16) + (u8(b, i + 2) << 8) + u8(b, i + 3);
|
|
80
|
+
}
|
|
81
|
+
function readImageHeader(b) {
|
|
82
|
+
if (b.startsWith('\x89PNG\r\n\x1a\n'))
|
|
83
|
+
return readPng(b);
|
|
84
|
+
if (b.startsWith('GIF87a') || b.startsWith('GIF89a'))
|
|
85
|
+
return readGif(b);
|
|
86
|
+
if (b.startsWith('RIFF') && b.slice(8, 12) === 'WEBP')
|
|
87
|
+
return readWebp(b);
|
|
88
|
+
if (u8(b, 0) === 0xff && u8(b, 1) === 0xd8)
|
|
89
|
+
return readJpeg(b);
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
function readPng(b) {
|
|
93
|
+
// The first chunk is IHDR: width and height are big-endian uint32 at 16 and 20
|
|
94
|
+
if (b.length < 24 || b.slice(12, 16) !== 'IHDR')
|
|
95
|
+
return null;
|
|
96
|
+
return { mimeType: 'image/png', width: u32be(b, 16), height: u32be(b, 20) };
|
|
97
|
+
}
|
|
98
|
+
function readGif(b) {
|
|
99
|
+
if (b.length < 10)
|
|
100
|
+
return null;
|
|
101
|
+
return { mimeType: 'image/gif', width: u16le(b, 6), height: u16le(b, 8) };
|
|
102
|
+
}
|
|
103
|
+
function readWebp(b) {
|
|
104
|
+
const chunk = b.slice(12, 16);
|
|
105
|
+
if (chunk === 'VP8 ') {
|
|
106
|
+
if (b.length < 30)
|
|
107
|
+
return null;
|
|
108
|
+
return {
|
|
109
|
+
mimeType: 'image/webp',
|
|
110
|
+
width: u16le(b, 26) & 0x3fff,
|
|
111
|
+
height: u16le(b, 28) & 0x3fff,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
if (chunk === 'VP8L') {
|
|
115
|
+
if (b.length < 25)
|
|
116
|
+
return null;
|
|
117
|
+
const b0 = u8(b, 21);
|
|
118
|
+
const b1 = u8(b, 22);
|
|
119
|
+
const b2 = u8(b, 23);
|
|
120
|
+
const b3 = u8(b, 24);
|
|
121
|
+
return {
|
|
122
|
+
mimeType: 'image/webp',
|
|
123
|
+
width: 1 + (((b1 & 0x3f) << 8) | b0),
|
|
124
|
+
height: 1 + (((b3 & 0x0f) << 10) | (b2 << 2) | ((b1 & 0xc0) >> 6)),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
if (chunk === 'VP8X') {
|
|
128
|
+
if (b.length < 30)
|
|
129
|
+
return null;
|
|
130
|
+
return { mimeType: 'image/webp', width: 1 + u24le(b, 24), height: 1 + u24le(b, 27) };
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
function readJpeg(b) {
|
|
135
|
+
let i = 2;
|
|
136
|
+
while (i + 3 < b.length) {
|
|
137
|
+
if (u8(b, i) !== 0xff)
|
|
138
|
+
return null;
|
|
139
|
+
const marker = u8(b, i + 1);
|
|
140
|
+
if (marker === 0xff) {
|
|
141
|
+
// Fill byte
|
|
142
|
+
i += 1;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
// Markers without a length field
|
|
146
|
+
if (marker === 0x01 || (marker >= 0xd0 && marker <= 0xd8)) {
|
|
147
|
+
i += 2;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
// SOF0..SOF15 except DHT (C4), JPG (C8) and DAC (CC) carry the frame size
|
|
151
|
+
if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) {
|
|
152
|
+
if (i + 9 > b.length)
|
|
153
|
+
return null;
|
|
154
|
+
return { mimeType: 'image/jpeg', width: u16be(b, i + 7), height: u16be(b, i + 5) };
|
|
155
|
+
}
|
|
156
|
+
if (marker === 0xd9 || marker === 0xda)
|
|
157
|
+
return null;
|
|
158
|
+
i += 2 + u16be(b, i + 2);
|
|
159
|
+
}
|
|
160
|
+
return null;
|
|
161
|
+
}
|