@guidelytech/shared 0.14.0 → 0.16.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/dist/runtime.cjs CHANGED
@@ -28,6 +28,7 @@ __export(runtime_exports, {
28
28
  AGENT_TURNS_PER_BATCH: () => AGENT_TURNS_PER_BATCH,
29
29
  AGENT_TURN_MAX_TEXT: () => AGENT_TURN_MAX_TEXT,
30
30
  AGENT_TURN_ROLES: () => AGENT_TURN_ROLES,
31
+ ARTICLE_HREF_PREFIX: () => ARTICLE_HREF_PREFIX,
31
32
  ARTICLE_VISIBILITIES: () => ARTICLE_VISIBILITIES,
32
33
  CAPTURE_PARAM: () => CAPTURE_PARAM,
33
34
  CAPTURE_SCREENSHOT_MAX_BYTES: () => CAPTURE_SCREENSHOT_MAX_BYTES,
@@ -96,6 +97,8 @@ __export(runtime_exports, {
96
97
  WS_MAX_MESSAGES_PER_SOCKET: () => WS_MAX_MESSAGES_PER_SOCKET,
97
98
  WS_MAX_MESSAGE_BYTES: () => WS_MAX_MESSAGE_BYTES,
98
99
  applyGuideTranslations: () => applyGuideTranslations,
100
+ articleHref: () => articleHref,
101
+ articleIdFromHref: () => articleIdFromHref,
99
102
  articleTextEntries: () => articleTextEntries,
100
103
  assignGuideVariant: () => assignGuideVariant,
101
104
  baseLanguage: () => baseLanguage,
@@ -137,6 +140,7 @@ __export(runtime_exports, {
137
140
  isRuleGroup: () => isRuleGroup,
138
141
  isSafeMediaUrl: () => isSafeMediaUrl,
139
142
  isVideoContentType: () => isVideoContentType,
143
+ isVideoFileUrl: () => isVideoFileUrl,
140
144
  localeName: () => localeName,
141
145
  localizeAnnouncement: () => localizeAnnouncement,
142
146
  localizeArticle: () => localizeArticle,
@@ -185,6 +189,7 @@ __export(runtime_exports, {
185
189
  slugify: () => slugify,
186
190
  snapshotFromSelector: () => snapshotFromSelector,
187
191
  stableStringify: () => stableStringify,
192
+ stepVideo: () => stepVideo,
188
193
  stripOrigin: () => stripOrigin,
189
194
  supportsPlatform: () => supportsPlatform,
190
195
  toEmbedUrl: () => toEmbedUrl,
@@ -192,6 +197,7 @@ __export(runtime_exports, {
192
197
  unreadAnnouncements: () => unreadAnnouncements,
193
198
  variantProblems: () => variantProblems,
194
199
  variantRanges: () => variantRanges,
200
+ videoThumbnailUrl: () => videoThumbnailUrl,
195
201
  visibleAnnouncements: () => visibleAnnouncements,
196
202
  visibleArticleIds: () => visibleArticleIds,
197
203
  visitorAudiences: () => visitorAudiences,
@@ -775,6 +781,19 @@ function isSafeMediaUrl(url) {
775
781
  return false;
776
782
  }
777
783
  }
784
+ function videoThumbnailUrl(url) {
785
+ const embed = url ? toEmbedUrl(url) : null;
786
+ if (embed?.provider !== "youtube") return null;
787
+ const id = embed.src.split("/embed/")[1]?.split("?")[0];
788
+ return id ? `https://i.ytimg.com/vi/${id}/hqdefault.jpg` : null;
789
+ }
790
+ function isVideoFileUrl(url) {
791
+ return isSafeMediaUrl(url) && /\.(mp4|webm|m4v|mov|ogv)$/i.test(new URL(url).pathname);
792
+ }
793
+ function stepVideo(step) {
794
+ if (!step.videoUrl || !isSafeMediaUrl(step.videoUrl)) return null;
795
+ return { url: step.videoUrl, poster: (step.imageUrl && isSafeMediaUrl(step.imageUrl) ? step.imageUrl : null) ?? videoThumbnailUrl(step.videoUrl) };
796
+ }
778
797
 
779
798
  // src/resource-center.ts
780
799
  var MAX_COLLECTION_DEPTH = 3;
@@ -897,6 +916,16 @@ function unreadAnnouncements(items, lastSeenAt) {
897
916
  if (Number.isNaN(seen)) return items.length;
898
917
  return items.filter((a) => Date.parse(a.publishedAt) > seen).length;
899
918
  }
919
+ var ARTICLE_HREF_PREFIX = "#guidely-article:";
920
+ var ARTICLE_ID = /^[A-Za-z0-9_-]{1,64}$/;
921
+ function articleHref(articleId) {
922
+ return `${ARTICLE_HREF_PREFIX}${articleId}`;
923
+ }
924
+ function articleIdFromHref(href) {
925
+ if (!href || !href.startsWith(ARTICLE_HREF_PREFIX)) return null;
926
+ const id = href.slice(ARTICLE_HREF_PREFIX.length);
927
+ return ARTICLE_ID.test(id) ? id : null;
928
+ }
900
929
 
901
930
  // src/howto-limits.ts
902
931
  var CAPTURE_PARAM = "guidely_capture";
@@ -1970,6 +1999,7 @@ function contrastIssues(colors) {
1970
1999
  AGENT_TURNS_PER_BATCH,
1971
2000
  AGENT_TURN_MAX_TEXT,
1972
2001
  AGENT_TURN_ROLES,
2002
+ ARTICLE_HREF_PREFIX,
1973
2003
  ARTICLE_VISIBILITIES,
1974
2004
  CAPTURE_PARAM,
1975
2005
  CAPTURE_SCREENSHOT_MAX_BYTES,
@@ -2038,6 +2068,8 @@ function contrastIssues(colors) {
2038
2068
  WS_MAX_MESSAGES_PER_SOCKET,
2039
2069
  WS_MAX_MESSAGE_BYTES,
2040
2070
  applyGuideTranslations,
2071
+ articleHref,
2072
+ articleIdFromHref,
2041
2073
  articleTextEntries,
2042
2074
  assignGuideVariant,
2043
2075
  baseLanguage,
@@ -2079,6 +2111,7 @@ function contrastIssues(colors) {
2079
2111
  isRuleGroup,
2080
2112
  isSafeMediaUrl,
2081
2113
  isVideoContentType,
2114
+ isVideoFileUrl,
2082
2115
  localeName,
2083
2116
  localizeAnnouncement,
2084
2117
  localizeArticle,
@@ -2127,6 +2160,7 @@ function contrastIssues(colors) {
2127
2160
  slugify,
2128
2161
  snapshotFromSelector,
2129
2162
  stableStringify,
2163
+ stepVideo,
2130
2164
  stripOrigin,
2131
2165
  supportsPlatform,
2132
2166
  toEmbedUrl,
@@ -2134,6 +2168,7 @@ function contrastIssues(colors) {
2134
2168
  unreadAnnouncements,
2135
2169
  variantProblems,
2136
2170
  variantRanges,
2171
+ videoThumbnailUrl,
2137
2172
  visibleAnnouncements,
2138
2173
  visibleArticleIds,
2139
2174
  visitorAudiences,