Current section

Files

Jump to
inlay src inlay@inline.erl
Raw

src/inlay@inline.erl

-module(inlay@inline).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/inlay/inline.gleam").
-export([bluesky_iframe/3, tweet_iframe/2, instagram_iframe/3, tiktok_iframe/2, mastodon_iframe/4, pixelfed_iframe/4]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Self-contained iframe rendering for the `<inlay-embed>` Lustre component.\n"
"\n"
" A Lustre component always renders into a shadow root. Several providers ship\n"
" a placeholder plus a host-page script that scans the document with\n"
" `querySelectorAll` to hydrate or resize the embed, and that scan cannot\n"
" reach inside a shadow root. For those providers this module renders the\n"
" embed as a self-contained `<iframe>` that points at the provider's own embed\n"
" page, which needs no host-page script and works inside the shadow root.\n"
"\n"
" The static (`inlay.render`) path keeps using the script-based embeds, which\n"
" work in plain light-DOM HTML\n"
).
-file("src/inlay/inline.gleam", 81).
-spec frame(binary(), binary(), integer()) -> lustre@vdom@vnode:element(any()).
frame(Src, Title, Height) ->
lustre@element@html:iframe(
[lustre@attribute:attribute(<<"title"/utf8>>, Title),
lustre@attribute:src(Src),
lustre@attribute:class(<<"inlay-embed-frame"/utf8>>),
lustre@attribute:styles(
[{<<"width"/utf8>>, <<"100%"/utf8>>},
{<<"border"/utf8>>, <<"0"/utf8>>},
{<<"height"/utf8>>,
<<(erlang:integer_to_binary(Height))/binary, "px"/utf8>>}]
),
lustre@attribute:attribute(<<"scrolling"/utf8>>, <<"no"/utf8>>),
lustre@attribute:attribute(
<<"allowfullscreen"/utf8>>,
<<"true"/utf8>>
),
lustre@attribute:attribute(<<"loading"/utf8>>, <<"lazy"/utf8>>),
lustre@attribute:attribute(
<<"sandbox"/utf8>>,
<<"allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox allow-presentation"/utf8>>
)]
).
-file("src/inlay/inline.gleam", 25).
?DOC(" Render a Bluesky post as a self-contained embed iframe for a resolved DID.\n").
-spec bluesky_iframe(binary(), binary(), integer()) -> lustre@vdom@vnode:element(any()).
bluesky_iframe(Did, Rkey, Height) ->
Src = <<<<<<"https://embed.bsky.app/embed/"/utf8, Did/binary>>/binary,
"/app.bsky.feed.post/"/utf8>>/binary,
Rkey/binary>>,
frame(Src, <<"Bluesky post"/utf8>>, Height).
-file("src/inlay/inline.gleam", 32).
?DOC(" Render a Tweet as a self-contained embed iframe.\n").
-spec tweet_iframe(binary(), integer()) -> lustre@vdom@vnode:element(any()).
tweet_iframe(Id, Height) ->
Src = <<"https://platform.twitter.com/embed/Tweet.html?id="/utf8,
Id/binary>>,
frame(Src, <<"Tweet"/utf8>>, Height).
-file("src/inlay/inline.gleam", 38).
?DOC(" Render an Instagram post as a self-contained embed iframe.\n").
-spec instagram_iframe(inlay@embed:instagram_post_type(), binary(), integer()) -> lustre@vdom@vnode:element(any()).
instagram_iframe(Post_type, Id, Height) ->
Type_segment = case Post_type of
post ->
<<"p"/utf8>>;
reel ->
<<"reel"/utf8>>;
t_v ->
<<"tv"/utf8>>
end,
Src = <<<<<<<<"https://www.instagram.com/"/utf8, Type_segment/binary>>/binary,
"/"/utf8>>/binary,
Id/binary>>/binary,
"/embed/"/utf8>>,
frame(Src, <<"Instagram post"/utf8>>, Height).
-file("src/inlay/inline.gleam", 54).
?DOC(" Render a TikTok video as a self-contained embed iframe.\n").
-spec tiktok_iframe(binary(), integer()) -> lustre@vdom@vnode:element(any()).
tiktok_iframe(Id, Height) ->
Src = <<"https://www.tiktok.com/embed/v2/"/utf8, Id/binary>>,
frame(Src, <<"TikTok video"/utf8>>, Height).
-file("src/inlay/inline.gleam", 60).
?DOC(" Render a Mastodon post as a self-contained embed iframe.\n").
-spec mastodon_iframe(binary(), binary(), binary(), integer()) -> lustre@vdom@vnode:element(any()).
mastodon_iframe(Server, User, Id, Height) ->
Src = <<<<<<<<<<<<"https://"/utf8, Server/binary>>/binary, "/@"/utf8>>/binary,
User/binary>>/binary,
"/"/utf8>>/binary,
Id/binary>>/binary,
"/embed"/utf8>>,
frame(Src, <<"Mastodon post"/utf8>>, Height).
-file("src/inlay/inline.gleam", 71).
?DOC(" Render a Pixelfed post as a self-contained embed iframe.\n").
-spec pixelfed_iframe(binary(), binary(), binary(), integer()) -> lustre@vdom@vnode:element(any()).
pixelfed_iframe(Server, User, Id, Height) ->
Src = <<<<<<<<<<<<"https://"/utf8, Server/binary>>/binary, "/p/"/utf8>>/binary,
User/binary>>/binary,
"/"/utf8>>/binary,
Id/binary>>/binary,
"/embed"/utf8>>,
frame(Src, <<"Pixelfed post"/utf8>>, Height).