@ibodr/draw 0.1.0 → 0.1.1

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/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { useMaybeEditor, uniqueId, useValue, assert, useReactor, unsafe__withoutCapture, useContainer, debugFlags, objectMapValues, WeakCache, tltime, tlenv, track, useEditor, usePassThroughWheelEvents, useEditorComponents, preventDefault, PageRecordType, setPointerCapture, releasePointerCapture, usePresence, USER_COLORS, modulate, isEqual, approximately, Box, debounce, isEqualAllowingForFloatingPointErrors, createComputedCache as createComputedCache$1, useUniqueSafeId, useEvent, toRichText, Vec, getChangedKeys, useSharedSafeId, useIsEditing, toDomPrecision, LruCache, HTMLContainer, MediaHelpers, Image, getGlobalDocument, getDefaultCdnBaseUrl, LANGUAGES, defaultUserPreferences, useShallowArrayIdentity, mergeArraysAndReplaceDefaults, useDrStore, Editor as Editor$1, T, registerDrawLibraryVersion, safeParseUrl, useGlobalMenuIsOpen, getFromLocalStorage, setInLocalStorage, getIndexAbove, getIndexBelow, getIndexBetween, exhaustiveSwitchError, getOwnerWindow, DefaultColorStyle, getColorValue, tlmenus, SharedStyleMap, DefaultDashStyle, DefaultFillStyle, DefaultSizeStyle, kickoutOccludedShapes, usePassThroughMouseOverEvents, useAtom, react, lerp, isSafeFloat, Mat, isAccelKey, openWindow, Polyline2d, Arc2d, Edge2d, useSvgExportContext, useColorMode, getVerticesCountForArcLength, Group2d, assertExists, clamp, rng, canonicalizeRotation, getPolygonVertices, useDelaySvgExport, noop, getGlobalWindow, useShallowObjectIdentity, objectMapEntries, GeoShapeGeoStyle, ShapeUtil, textShapeProps, textShapeMigrations, Rectangle2d, getFontsFromRichText, resizeScaled, BaseBoxShapeUtil, bookmarkShapeProps, bookmarkShapeMigrations, drawShapeProps, drawShapeMigrations, Circle2d, Polygon2d, SVGContainer, last, geoShapeProps, geoShapeMigrations, EMPTY_ARRAY, noteShapeProps, noteShapeMigrations, DefaultFontFamilies, lineShapeProps, lineShapeMigrations, getIndices, sortByIndex, mapObjectMapValues, maybeSnapToGrid, ZERO_INDEX_KEY, BaseFrameLikeShapeUtil, frameShapeProps, frameShapeMigrations, compact, arrowShapeProps, arrowShapeMigrations, invLerp, structuredClone, highlightShapeProps, highlightShapeMigrations, tlenvReactive, embedShapeProps, embedShapeMigrations, resizeBox, imageShapeProps, imageShapeMigrations, createShapeId, Ellipse2d, videoShapeProps, videoShapeMigrations, BindingUtil, arrowBindingProps, arrowBindingMigrations, getOwnProperty, atom, DefaultSpinner, elementShouldCaptureKeys, minBy, DefaultFontStyle, DefaultTextAlignStyle, DefaultHorizontalAlignStyle, DefaultVerticalAlignStyle, ArrowShapeKindStyle, ArrowShapeArrowheadEndStyle, ArrowShapeArrowheadStartStyle, LineShapeSplineStyle, activeElementShouldCaptureKeys, Geometry2dFilters, pointInPolygon, intersectLineSegmentPolygon, centerOfCircleFromThreePoints, clockwiseAngleDist, counterClockwiseAngleDist, PI, getPointerInfo, intersectCircleCircle, HALF_PI, suffixSafeId, getPerfectDashProps, Geometry2d, CubicBezier2d, usePeerIds, normalizeWheel, getIndicesBetween, AssetRecordType, getHashForString, precise, average, b64Vecs, computed, objectMapKeys, intersectLineSegmentCircle, EASINGS, fetch, FileHelpers, isFontEntry, PI2, isDefined, hardResetEditor, sanitizeId, Result, transact, isShapeId, richTextValidator, featureFlags, useQuickReactor, objectMapFromEntries, uniq, ShapeIndicatorOverlayUtil, createBindingId, getHashForBuffer, bind, getPointOnCircle, AssetUtil, bookmarkAssetProps, bookmarkAssetMigrations, clampToBrowserMaxCanvasSize, imageAssetProps, imageAssetMigrations, DEFAULT_SUPPORTED_IMAGE_TYPES, videoAssetProps, videoAssetMigrations, DEFAULT_SUPPORT_VIDEO_TYPES, OverlayUtil, getOverlayDisplayValues, getSvgPathFromPoints, strokeShapeIndicators, SIDES, rangeIntersection, StateNode, BaseBoxShapeTool, DrawEditor, useOnMount, createDrStore, MigrationFailureReason, toFixed, snapAngle, isPageId, polygonsIntersect, areAnglesCompatible, getRotationSnapshot, applyRotationToSnapshotShapes, shortAngleDist, degreesToRadians, warnOnce, LoadingScreen as LoadingScreen$1, SIN, throttle } from '@ibodr/editor';
1
+ import { useMaybeEditor, uniqueId, useValue, assert, useReactor, unsafe__withoutCapture, useContainer, debugFlags, objectMapValues, WeakCache, tltime, tlenv, track, useEditor, usePassThroughWheelEvents, useEditorComponents, preventDefault, PageRecordType, setPointerCapture, releasePointerCapture, usePresence, USER_COLORS, modulate, isEqual, approximately, Box, debounce, isEqualAllowingForFloatingPointErrors, createComputedCache as createComputedCache$1, useUniqueSafeId, useEvent, toRichText, Vec, getChangedKeys, useSharedSafeId, useIsEditing, toDomPrecision, LruCache, HTMLContainer, MediaHelpers, Image, getGlobalDocument, getDefaultCdnBaseUrl, defaultUserPreferences, useShallowArrayIdentity, mergeArraysAndReplaceDefaults, useDrStore, Editor as Editor$1, T, registerDrawLibraryVersion, safeParseUrl, useGlobalMenuIsOpen, getFromLocalStorage, setInLocalStorage, getIndexAbove, getIndexBelow, getIndexBetween, exhaustiveSwitchError, getOwnerWindow, DefaultColorStyle, getColorValue, tlmenus, SharedStyleMap, DefaultDashStyle, DefaultFillStyle, DefaultSizeStyle, kickoutOccludedShapes, usePassThroughMouseOverEvents, useAtom, react, lerp, isSafeFloat, Mat, isAccelKey, openWindow, Polyline2d, Arc2d, Edge2d, useSvgExportContext, useColorMode, getVerticesCountForArcLength, Group2d, assertExists, clamp, rng, canonicalizeRotation, getPolygonVertices, useDelaySvgExport, noop, getGlobalWindow, useShallowObjectIdentity, objectMapEntries, GeoShapeGeoStyle, ShapeUtil, textShapeProps, textShapeMigrations, Rectangle2d, getFontsFromRichText, resizeScaled, BaseBoxShapeUtil, bookmarkShapeProps, bookmarkShapeMigrations, drawShapeProps, drawShapeMigrations, Circle2d, Polygon2d, SVGContainer, last, geoShapeProps, geoShapeMigrations, EMPTY_ARRAY, noteShapeProps, noteShapeMigrations, DefaultFontFamilies, lineShapeProps, lineShapeMigrations, getIndices, sortByIndex, mapObjectMapValues, maybeSnapToGrid, ZERO_INDEX_KEY, BaseFrameLikeShapeUtil, frameShapeProps, frameShapeMigrations, compact, arrowShapeProps, arrowShapeMigrations, invLerp, structuredClone, highlightShapeProps, highlightShapeMigrations, tlenvReactive, embedShapeProps, embedShapeMigrations, resizeBox, imageShapeProps, imageShapeMigrations, createShapeId, Ellipse2d, videoShapeProps, videoShapeMigrations, BindingUtil, arrowBindingProps, arrowBindingMigrations, getOwnProperty, atom, DefaultSpinner, elementShouldCaptureKeys, minBy, DefaultFontStyle, DefaultTextAlignStyle, DefaultHorizontalAlignStyle, DefaultVerticalAlignStyle, ArrowShapeKindStyle, ArrowShapeArrowheadEndStyle, ArrowShapeArrowheadStartStyle, LineShapeSplineStyle, activeElementShouldCaptureKeys, Geometry2dFilters, pointInPolygon, intersectLineSegmentPolygon, centerOfCircleFromThreePoints, clockwiseAngleDist, counterClockwiseAngleDist, PI, getPointerInfo, intersectCircleCircle, HALF_PI, suffixSafeId, getPerfectDashProps, Geometry2d, CubicBezier2d, LANGUAGES, usePeerIds, normalizeWheel, getIndicesBetween, AssetRecordType, getHashForString, precise, average, b64Vecs, computed, objectMapKeys, intersectLineSegmentCircle, EASINGS, fetch, FileHelpers, isFontEntry, PI2, isDefined, hardResetEditor, sanitizeId, Result, transact, isShapeId, richTextValidator, featureFlags, useQuickReactor, objectMapFromEntries, uniq, ShapeIndicatorOverlayUtil, createBindingId, getHashForBuffer, bind, getPointOnCircle, AssetUtil, bookmarkAssetProps, bookmarkAssetMigrations, clampToBrowserMaxCanvasSize, imageAssetProps, imageAssetMigrations, DEFAULT_SUPPORTED_IMAGE_TYPES, videoAssetProps, videoAssetMigrations, DEFAULT_SUPPORT_VIDEO_TYPES, OverlayUtil, getOverlayDisplayValues, getSvgPathFromPoints, strokeShapeIndicators, SIDES, rangeIntersection, StateNode, BaseBoxShapeTool, DrawEditor, useOnMount, createDrStore, MigrationFailureReason, toFixed, snapAngle, isPageId, polygonsIntersect, areAnglesCompatible, getRotationSnapshot, applyRotationToSnapshotShapes, shortAngleDist, degreesToRadians, warnOnce, LoadingScreen as LoadingScreen$1, SIN, throttle } from '@ibodr/editor';
2
2
  export * from '@ibodr/editor';
3
3
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
4
4
  import * as React4 from 'react';
@@ -1560,36 +1560,6 @@ function useA11y() {
1560
1560
  }
1561
1561
  return ctx;
1562
1562
  }
1563
- var AssetUrlsContext = createContext(null);
1564
- function AssetUrlsProvider({
1565
- assetUrls,
1566
- children
1567
- }) {
1568
- useEffect(() => {
1569
- for (const src of Object.values(assetUrls.icons)) {
1570
- if (!src) continue;
1571
- const image = Image();
1572
- image.crossOrigin = "anonymous";
1573
- image.src = src;
1574
- image.decode().catch(noop);
1575
- }
1576
- for (const src of Object.values(assetUrls.embedIcons)) {
1577
- if (!src) continue;
1578
- const image = Image();
1579
- image.crossOrigin = "anonymous";
1580
- image.src = src;
1581
- image.decode().catch(noop);
1582
- }
1583
- }, [assetUrls]);
1584
- return /* @__PURE__ */ jsx(AssetUrlsContext.Provider, { value: assetUrls, children });
1585
- }
1586
- function useAssetUrls() {
1587
- const assetUrls = useContext(AssetUrlsContext);
1588
- if (!assetUrls) {
1589
- throw new Error("useAssetUrls must be used within an AssetUrlsProvider");
1590
- }
1591
- return assetUrls;
1592
- }
1593
1563
 
1594
1564
  // src/lib/ui/hooks/useTranslation/defaultTranslation.ts
1595
1565
  var DEFAULT_TRANSLATION = {
@@ -2096,41 +2066,19 @@ var EN_TRANSLATION = {
2096
2066
  messages: DEFAULT_TRANSLATION,
2097
2067
  dir: "ltr"
2098
2068
  };
2099
- async function fetchTranslation(locale, assetUrls) {
2100
- const mainRes = await fetch(assetUrls.translations.en);
2101
- if (!mainRes.ok) {
2102
- console.warn(`No main translations found.`);
2103
- return EN_TRANSLATION;
2104
- }
2069
+ function getTranslation(locale) {
2105
2070
  if (locale === "en") {
2106
2071
  return EN_TRANSLATION;
2107
2072
  }
2108
2073
  const language = LANGUAGES.find((t2) => t2.locale === locale);
2109
2074
  if (!language) {
2110
- console.warn(`No translation found for locale ${locale}`);
2111
- return EN_TRANSLATION;
2112
- }
2113
- const res = await fetch(assetUrls.translations[language.locale]);
2114
- const messages = await res.json();
2115
- if (!messages) {
2116
- console.warn(`No messages found for locale ${locale}`);
2117
2075
  return EN_TRANSLATION;
2118
2076
  }
2119
- const missing = [];
2120
- for (const key in EN_TRANSLATION.messages) {
2121
- if (!messages[key]) {
2122
- missing.push(key);
2123
- }
2124
- }
2125
- if (missing.length > 0 && true) {
2126
- console.warn(`Language ${locale}: missing messages for keys:
2127
- ${missing.join("\n")}`);
2128
- }
2129
2077
  return {
2130
2078
  locale,
2131
2079
  label: language.label,
2132
2080
  dir: RTL_LANGUAGES.has(language.locale) ? "rtl" : "ltr",
2133
- messages: { ...EN_TRANSLATION.messages, ...messages }
2081
+ messages: EN_TRANSLATION.messages
2134
2082
  };
2135
2083
  }
2136
2084
  var TranslationsContext = React4.createContext(null);
@@ -2146,43 +2094,16 @@ function DrawUiTranslationProvider({
2146
2094
  locale,
2147
2095
  children
2148
2096
  }) {
2149
- const getAssetUrl = useAssetUrls();
2150
- const [currentTranslation, setCurrentTranslation] = React4.useState(() => {
2151
- if (overrides && overrides["en"]) {
2097
+ const currentTranslation = React4.useMemo(() => {
2098
+ const translation = getTranslation(locale);
2099
+ if (overrides?.[locale]) {
2152
2100
  return {
2153
- locale: "en",
2154
- label: "English",
2155
- dir: "ltr",
2156
- messages: { ...DEFAULT_TRANSLATION, ...overrides["en"] }
2101
+ ...translation,
2102
+ messages: { ...translation.messages, ...overrides[locale] }
2157
2103
  };
2158
2104
  }
2159
- return {
2160
- locale: "en",
2161
- label: "English",
2162
- dir: "ltr",
2163
- messages: DEFAULT_TRANSLATION
2164
- };
2165
- });
2166
- React4.useEffect(() => {
2167
- let isCancelled = false;
2168
- async function loadTranslation() {
2169
- const translation = await fetchTranslation(locale, getAssetUrl);
2170
- if (translation && !isCancelled) {
2171
- if (overrides && overrides[locale]) {
2172
- setCurrentTranslation({
2173
- ...translation,
2174
- messages: { ...translation.messages, ...overrides[locale] }
2175
- });
2176
- } else {
2177
- setCurrentTranslation(translation);
2178
- }
2179
- }
2180
- }
2181
- loadTranslation();
2182
- return () => {
2183
- isCancelled = true;
2184
- };
2185
- }, [getAssetUrl, locale, overrides]);
2105
+ return translation;
2106
+ }, [locale, overrides]);
2186
2107
  return /* @__PURE__ */ jsx(TranslationsContext.Provider, { value: currentTranslation, children });
2187
2108
  }
2188
2109
  function useTranslation() {
@@ -4737,6 +4658,36 @@ function fitFrameToContent(editor, id, opts = {}) {
4737
4658
  function DrawUiButtonLabel({ children }) {
4738
4659
  return /* @__PURE__ */ jsx("span", { className: "tlui-button__label", children });
4739
4660
  }
4661
+ var AssetUrlsContext = createContext(null);
4662
+ function AssetUrlsProvider({
4663
+ assetUrls,
4664
+ children
4665
+ }) {
4666
+ useEffect(() => {
4667
+ for (const src of Object.values(assetUrls.icons)) {
4668
+ if (!src) continue;
4669
+ const image = Image();
4670
+ image.crossOrigin = "anonymous";
4671
+ image.src = src;
4672
+ image.decode().catch(noop);
4673
+ }
4674
+ for (const src of Object.values(assetUrls.embedIcons)) {
4675
+ if (!src) continue;
4676
+ const image = Image();
4677
+ image.crossOrigin = "anonymous";
4678
+ image.src = src;
4679
+ image.decode().catch(noop);
4680
+ }
4681
+ }, [assetUrls]);
4682
+ return /* @__PURE__ */ jsx(AssetUrlsContext.Provider, { value: assetUrls, children });
4683
+ }
4684
+ function useAssetUrls() {
4685
+ const assetUrls = useContext(AssetUrlsContext);
4686
+ if (!assetUrls) {
4687
+ throw new Error("useAssetUrls must be used within an AssetUrlsProvider");
4688
+ }
4689
+ return assetUrls;
4690
+ }
4740
4691
  var DrawUiIcon = memo(function DrawUiIcon2({
4741
4692
  label,
4742
4693
  small,
@@ -35250,12 +35201,7 @@ var defaultUiAssetUrls = {
35250
35201
  icons: Object.fromEntries(
35251
35202
  iconTypes.map((name) => [name, `${getDefaultCdnBaseUrl()}/icons/icon/0_merged.svg#${name}`])
35252
35203
  ),
35253
- translations: Object.fromEntries(
35254
- LANGUAGES.map((lang) => [
35255
- lang.locale,
35256
- `${getDefaultCdnBaseUrl()}/translations/${lang.locale}.json`
35257
- ])
35258
- ),
35204
+ translations: {},
35259
35205
  embedIcons: Object.fromEntries(
35260
35206
  DEFAULT_EMBED_DEFINITIONS.map((def) => [
35261
35207
  def.type,
@@ -37026,7 +36972,7 @@ async function extractAssets(editor, snapshot, msg, addToast) {
37026
36972
  // src/index.ts
37027
36973
  registerDrawLibraryVersion(
37028
36974
  "@ibodr/draw",
37029
- "0.1.0",
36975
+ "0.1.1",
37030
36976
  "esm"
37031
36977
  );
37032
36978
  /*!