@miroart/sdk 0.3.0 → 0.4.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.
@@ -0,0 +1,45 @@
1
+ import { type PropType, type VNode } from "vue";
2
+ import { type OrderPathPart } from "./order";
3
+ /**
4
+ * Kolejność elementów strony, którą można zmienić w edytorze wizualnym.
5
+ *
6
+ * Stałe bloki szablonu: `<MiroOrder name="home"><template #hero>…</template></MiroOrder>`.
7
+ * Kolejność jest w opcji `miro_order`, a slot nazywa się po kluczu, nie po numerze.
8
+ *
9
+ * Lista z opcji: `<MiroOrder source="faq.items" :items="rows" v-slot="{ item, index }">`.
10
+ * Kolejność to sama tablica. Gdy `items` powstało przez filtr, `:at` podaje indeks w surowej tablicy.
11
+ *
12
+ * Sam komponent nie dokłada elementu do DOM, a poza ramką edytora także atrybutów.
13
+ */
14
+ export declare const MiroOrder: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
15
+ name: StringConstructor;
16
+ source: PropType<string | OrderPathPart[]>;
17
+ items: PropType<unknown[]>;
18
+ at: PropType<(item: never, position: number) => string | number>;
19
+ scope: {
20
+ type: PropType<"page" | "site">;
21
+ default: string;
22
+ };
23
+ locked: {
24
+ type: PropType<string[]>;
25
+ default: () => never[];
26
+ };
27
+ }>, () => VNode<import("vue").RendererNode, import("vue").RendererElement, {
28
+ [key: string]: any;
29
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
30
+ name: StringConstructor;
31
+ source: PropType<string | OrderPathPart[]>;
32
+ items: PropType<unknown[]>;
33
+ at: PropType<(item: never, position: number) => string | number>;
34
+ scope: {
35
+ type: PropType<"page" | "site">;
36
+ default: string;
37
+ };
38
+ locked: {
39
+ type: PropType<string[]>;
40
+ default: () => never[];
41
+ };
42
+ }>> & Readonly<{}>, {
43
+ scope: "page" | "site";
44
+ locked: string[];
45
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty,Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),e=["primary","secondary","accent","neutral","base-100","base-content","info","success","warning","error"],r=["sans","serif"],n=/\\(\[\/?(?:b|i|u|s|c|f)(?:=[a-z0-9-]+)?\])|\[(\/?)(b|i|u|s|c|f)(?:=([a-z0-9-]+))?\]/g;function s(t,n){return"c"===t?e.includes(n??""):"f"===t?r.includes(n??""):void 0===n}function i(t,e){""!==e&&e.split(/\r?\n/).forEach((e,r)=>{if(r>0&&t.push({type:"br"}),""===e)return;const n=t[t.length-1];"text"===n?.type?n.value+=e:t.push({type:"text",value:e})})}function o(t){const e=String(t??""),r=[],o=[],a=()=>o[o.length-1]?.children??r,c=()=>{var t,e;t=o.pop(),e=a(),0!==t.children.length&&("c"===t.tag?e.push({type:"c",value:t.value,children:t.children}):"f"===t.tag?e.push({type:"f",value:t.value,children:t.children}):e.push({type:t.tag,children:t.children}))};let u,l=0;for(n.lastIndex=0;null!==(u=n.exec(e));){i(a(),e.slice(l,u.index)),l=n.lastIndex;const[t,r,p,h,d]=u;if(void 0===r){if("/"===p){const e=void 0===d?o.map(t=>t.tag).lastIndexOf(h):-1;if(-1===e){i(a(),t);continue}for(;o.length>e;)c();continue}!s(h,d)||o.length>=8?i(a(),t):o.push({tag:h,value:d??null,children:[]})}else i(a(),r)}for(i(a(),e.slice(l));o.length>0;)c();return r}function a(t,e){for(const r of t)"text"===r.type?e.push(r.value):"br"===r.type?e.push("\n"):a(r.children,e)}function c(t){const e=String(t??"");if(!e.includes("["))return e;const r=[];return a(o(e),r),r.join("")}const u=/[⁢⁤][​‌‍⁠]+⁣/,l={b:"strong",i:"em",u:"u",s:"s"};function p(e){switch(e.type){case"text":return e.value;case"br":return t.h("br");case"c":return t.h("span",{style:{color:`var(--color-${e.value})`}},h(e.children));case"f":return t.h("span",{style:{fontFamily:`var(--font-${e.value})`}},h(e.children));default:return t.h(l[e.type],h(e.children))}}function h(t){return t.map(p)}const d=e=>{const r=t.toDisplayString(e.value),n=u.test(r);if(!n&&!function(t){return t.includes("[")||t.includes("\n")}(r))return r;const s=h(o(r));return n?t.h("span",{"data-miro-rich":"",style:{display:"contents"}},s):1===s.length?s[0]:s};function g(t,e){return{page:void 0!==e.page?e.page:t.page,site:void 0!==e.site?e.site:t.site,menus:e.menus?{...t.menus,...e.menus}:{...t.menus},locales:e.locales??t.locales,seo:void 0!==e.seo?e.seo:t.seo,options:e.options?{...t.options,...e.options}:{...t.options}}}function f(t){return Boolean(t)&&"object"==typeof t&&!Array.isArray(t)}function m(t){return f(t)?t:null}function y(t){return t?String(t.uuid||t.ulid||t.id||t.slug||t.full_url||""):""}function w(t){return t?String(t.uuid||t.domain||t.id||""):""}function S(t){return String.fromCharCode(...t.map(t=>23^t))}function b(t,e){const r=String(t||"").replace(/\/+$/,""),n=e.startsWith("/")?e:`/${e}`;return r?`${r}${n}`:n}function $(){const t=S([56,118,103,126]),e=S([97,38]),r=S([100,126,99,114,100]),n=S([103,118,112,114,100]),s=S([100,114,118,101,116,127]),i=S([122,114,121,98,100]),o=S([122,114,115,126,118]),a=S([103,123,98,112,126,121,100]),c=S([118,116,99,126,120,121,100]);return{sites:()=>b("",`${t}/${e}/${r}`),site:n=>b("",`${t}/${e}/${r}/${encodeURIComponent(n)}`),pages:s=>b("",`${t}/${e}/${r}/${encodeURIComponent(s)}/${n}`),page:(s,i)=>b("",`${t}/${e}/${r}/${encodeURIComponent(s)}/${n}/${i.split("/").map(t=>encodeURIComponent(t)).join("/")}`),search:i=>b("",`${t}/${e}/${r}/${encodeURIComponent(i)}/${n}/${s}`),menus:n=>b("",`${t}/${e}/${r}/${encodeURIComponent(n)}/${i}`),menu:(n,s)=>b("",`${t}/${e}/${r}/${encodeURIComponent(n)}/${i}/${encodeURIComponent(s)}`),media:e=>b("",`${t}/${o}/${encodeURIComponent(e)}`),action:e=>b("",`${t}/${c}/${encodeURIComponent(e)}`),plugins:(e,r,n="")=>{const s=`${t}/${a}/${encodeURIComponent(e)}/${encodeURIComponent(r)}`;return n&&"/"!==n?`${s}${n.startsWith("/")?n:`/${n}`}`:s}}}function x(){if("undefined"==typeof globalThis)return{};const t=globalThis.MiroConfig;return t&&"object"==typeof t?t:{}}function _(t){return t&&"object"==typeof t&&"data"in t?t.data:t}function j(t){return null==t?"":"string"==typeof t?t:"number"==typeof t||"boolean"==typeof t?String(t):""}function k(t){const e=j(t);if(!e)return"";if("undefined"!=typeof document){const t=document.createElement("textarea");return t.innerHTML=e,t.value}return e.replace(/&#(\d+);/g,(t,e)=>String.fromCharCode(Number(e))).replace(/&#x([0-9a-f]+);/gi,(t,e)=>String.fromCharCode(parseInt(e,16))).replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">")}function A(t){return c(k(t)).replace(/<script[\s\S]*?>[\s\S]*?<\/script>/gi," ").replace(/<style[\s\S]*?>[\s\S]*?<\/style>/gi," ").replace(/<[^>]+>/g," ").replace(/\s+/g," ").trim()}d.props=["value"],d.displayName="MiroText";class v extends String{kind;extra;constructor(t,e,r={}){super(k(e)),this.kind=t,this.extra=r,Object.setPrototypeOf(this,new.target.prototype)}toString(){return String.prototype.toString.call(this)}valueOf(){return String.prototype.valueOf.call(this)}raw(){return this.toString()}decode(){return k(this.toString())}cleanContent(){return A(this.toString())}stripHtml(){return this.cleanContent()}plain(){return c(this.toString())}excerpt(t=160){const e=this.cleanContent();return e.length<=t?e:`${e.slice(0,Math.max(0,t-1)).trimEnd()}…`}firstParagraph(){return function(t){const e=k(t),r=e.match(/<p\b[^>]*>([\s\S]*?)<\/p>/i);return A(r?r[1]:e)}(this.toString())}isEmpty(){return""===this.cleanContent()}json(){const t=this.toString().trim();if(!t)return null;try{return JSON.parse(t)}catch{return null}}bool(){const t=this.toString().trim().toLowerCase();return"1"===t||"true"===t||"yes"===t||"on"===t}number(){const t=Number(this.toString().trim());return Number.isFinite(t)?t:null}}class P extends v{constructor(t){super("PageTitle",t)}}class C extends v{constructor(t){super("PageSubtitle",t)}}class M extends v{constructor(t){super("PageSmallTitle",t)}}class T extends v{constructor(t){super("PageSummary",t)}}class O extends v{constructor(t){super("PageContent",t)}html(){return this.toString()}}class R extends v{constructor(t){super("SiteTitle",t)}}class I extends v{constructor(t){super("SiteName",t)}}class U extends v{key;structured;constructor(t,e){const r=E(e);super("OptionValue",r.text,{key:t}),this.key=t,this.structured=r.structured}json(){return void 0!==this.structured?this.structured:super.json()}present(){return!this.isEmpty()}}class N extends v{constructor(t){super("UrlValue",t)}path(){const t=this.toString().trim();if(!t)return"/";try{if(/^https?:\/\//i.test(t))return new URL(t).pathname.replace(/\/+$/,"")||"/"}catch{}return(t.startsWith("/")?t:`/${t}`).replace(/\/+$/,"")||"/"}href(t=""){const e=this.path();return!t||/^https?:\/\//i.test(e)?e:`${String(t).replace(/\/+$/,"")}${e}`}}class W extends v{constructor(t){super("MenuTitle",t)}}class L extends v{constructor(t){super("AssetName",t)}}class B extends v{constructor(t){super("SeoTitle",t)}}class q extends v{constructor(t){super("SeoDescription",t)}}function E(t){if(null==t)return{text:""};if("boolean"==typeof t||"number"==typeof t)return{text:String(t)};if("string"==typeof t){const e=t.trim();if(""===e||"[]"===e||"{}"===e)return{text:""};if(e.startsWith("{")&&e.endsWith("}")||e.startsWith("[")&&e.endsWith("]")||e.startsWith('"')&&e.endsWith('"'))try{return E(JSON.parse(e))}catch{return{text:k(t)}}return{text:k(t)}}return Array.isArray(t)?{text:JSON.stringify(t),structured:t}:"object"==typeof t?function(t){return"value"in t&&Object.keys(t).every(t=>"value"===t||"key"===t||"id"===t||"active"===t)}(t)?E(t.value):{text:JSON.stringify(t),structured:t}:{text:j(t)}}function G(t,e){if(!t)return"";if(Array.isArray(t)){const r=t.find(t=>t&&"object"==typeof t&&t.key===e);return r&&"object"==typeof r?r.value:""}return"object"==typeof t?t[e]:""}function D(t){if("string"==typeof t){const e=t.trim();return e?V(e)?{uuid:e}:{url:e,path:e}:null}if(!t||"object"!=typeof t||Array.isArray(t))return null;const e=t,r=F(e.source),n=z(e.url,e.preview_url,e.path,e.src,r?.url,r?.preview_url,r?.path),s=z(e.uuid,r?.uuid);if(n||s&&V(s))return e;const i=z(e.value);return i?D(i):null}function z(...t){for(const e of t)if("string"==typeof e&&""!==e.trim())return e.trim();return""}function J(t){return"string"==typeof t?t.trim():""}function F(t){return!t||"object"!=typeof t||Array.isArray(t)?null:t}function H(t){return t.startsWith("/media/")||t.startsWith("/_images/")||t.startsWith("/api/media/")||t.startsWith("/branding-assets/")||t.startsWith("/storage/")}function V(t){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t)}const K=[{mark:"1_8",width:256},{mark:"1_4",width:512},{mark:"1_2",width:1024},{mark:"2_3",width:1400}];class Z{constructor(t,e){this.record=t,this.runtime=e}record;runtime;getUuid(){return String(this.record.uuid||this.record.id||"")}getName(){return new L(this.record.name)}getAlt(){return J(this.record.alt)}getCaption(){return J(this.record.caption)}getGallery(){return this.memberships()[0]??null}galleryUuid(){return this.memberships()[0]?.uuid??""}galleryName(){return this.memberships()[0]?.name??""}memberships(){const t=this.record.galleries;if(Array.isArray(t)&&t.length>0)return t.map(t=>Q(t)).filter(t=>null!==t);const e=String(this.record.gallery_uuid??"").trim(),r=String(this.record.gallery_name??"").trim();if(!e&&!r)return[];const n=this.record.gallery_id;return[{id:"number"==typeof n||"string"==typeof n?n:null,uuid:e,name:r,sort_order:X(this.record.gallery_sort_order)}]}getMime(){const t=F(this.record.source);return String(this.record.mime_type||t?.mime_type||"")}getSize(){const t=F(this.record.source),e=Number(this.record.size??t?.size??0);return Number.isFinite(e)?e:0}getType(){const t=J(this.record.type);if(t)return t;const e=this.getMime();return e.startsWith("image/")?"image":e.startsWith("video/")?"video":"application/pdf"===e?"pdf":""}getSortOrder(){const t=Number(this.record.sort_order??0);return Number.isFinite(t)?t:0}isImage(){return!!this.getMime().startsWith("image/")||/\.(jpe?g|png|gif|webp|svg)(\?|$)/i.test(this.urlString())}url(){return new N(this.urlString())}srcset(){const t=this.urlString();if(!t||/\.svg([?#]|$)/i.test(t)||/^https?:\/\//i.test(t)||t.startsWith("//"))return"";if(!/\.webp([?#]|$)/i.test(t)||/\.(?:1_16|1_8|1_4|1_2|2_3)\.webp([?#]|$)/i.test(t))return"";const e=K.map(({mark:e,width:r})=>`${t.replace(/\.webp([?#].*)?$/i,`.${e}.webp$1`)} ${r}w`);return e.push(`${t} 2048w`),e.join(", ")}raw(){return{...this.record}}urlString(){const t=F(this.record.source),e=z(this.record.uuid,t?.uuid),r=z(this.record.disk,t?.disk);let n=z(this.record.url,this.record.preview_url,this.record.path,this.record.src,t?.url,t?.preview_url,t?.path);if(e&&V(e)&&n&&function(t,e){return!!(/\/project-storage\//i.test(r=t)||/\/editor\/project-file/i.test(r)||/cms\.miroart\.pl/i.test(r)&&/\/(?:project-storage|storage)\//i.test(r))||"project_public"===e&&!H(t)&&!/^https?:\/\//i.test(t)&&!t.startsWith("//");var r}(n,r))return this.mediaUrl(e);if(!n)return e&&V(e)?this.mediaUrl(e):"";if(!0===globalThis.isSsg){if(n.startsWith("/_images/")||n.startsWith("_images/"))return n.startsWith("/")?n:`/${n}`;const e=function(t){const e=t.match(/[?&]path=([^&]+)/i);if(e)try{const t=decodeURIComponent(e[1].replace(/\+/g," ")).split(/[/\\]/).pop()||"";if(t&&"project-file"!==t.toLowerCase())return t.trim()}catch{}return(t.split("#")[0].split("?")[0].split(/[/\\]/).pop()||"").trim()}(z(t?.path,this.record.path,n)),r=/\.(jpe?g|png|gif|webp|svg)$/i.test(s=e)?/\.svg$/i.test(s)?`/_images/${s}`:`/_images/${s.replace(/\.(jpe?g|png|gif|webp)$/i,".webp")}`:null;if(r)return r}var s;if(/^https?:\/\//i.test(n)||n.startsWith("//"))return n;if(n.startsWith("_images/"))return`/${n}`;if(H(n))return n;n.includes("/")||n.includes("\\")||V(n)||(n=`images/${n}`);const i=n.startsWith("/")?n:`/${n}`;return H(i)||i.startsWith("/project-storage/")?i:`/storage${i}`}mediaUrl(t){const e=$().media(t),r=this.runtime.apiBase();return r?b(r,e):e}}class Y{constructor(t){this.items=t}items;all(){return this.items.slice()}first(){return this.items[0]??null}extra(){return this.items.slice(1)}hero(){return this.first()}urls(){return this.items.map(t=>t.url())}isEmpty(){return 0===this.items.length}count(){return this.items.length}[Symbol.iterator](){return this.items[Symbol.iterator]()}}function Q(t){if(!t||"object"!=typeof t)return null;const e=t,r=String(e.uuid??"").trim(),n=String(e.name??"").trim();if(!r&&!n)return null;const s=e.id;return{id:"number"==typeof s||"string"==typeof s?s:null,uuid:r,name:n,sort_order:X(e.sort_order)}}function X(t){const e=Number(t??0);return Number.isFinite(e)?e:0}function tt(t,e){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new Z(t,e)):[]}const et=new Set(["id","uuid","created_at","updated_at"]);class rt{constructor(t,e){this.row=t,this.kernel=e}row;kernel;getHref(){return new N(this.row.href)}getTitle(){return String(this.row.title??"")}item(){const t=this.row.item;return t&&"object"==typeof t?t:{}}image(){return nt(this.item(),this.kernel)}}function nt(t,e){if(!t||"object"!=typeof t)return null;for(const[r,n]of Object.entries(t)){if(et.has(r)||"string"!=typeof n||!st(n))continue;const t=D(n);if(t)return new Z(t,e)}return null}function st(t){const e=t.trim();return!!e&&(!!(e.startsWith("/media/")||e.startsWith("/_images/")||e.startsWith("_images/")||e.startsWith("/api/media/")||e.startsWith("/branding-assets/"))||/\.(jpe?g|png|gif|webp|svg)(\?|#|$)/i.test(e))}function it(t,e){const r=t&&"object"==typeof t?t.meta:null,n=r&&"object"==typeof r?r:{};return{currentPage:at(n.current_page,1),lastPage:at(n.last_page,1),perPage:at(n.per_page,Math.max(e,1)),total:ct(n.total,e)}}function ot(t,e){return Object.assign(t,{meta:e})}function at(t,e){const r=Number(t);return!Number.isFinite(r)||r<1?e:Math.floor(r)}function ct(t,e){if(null==t||""===t)return e;const r=Number(t);return!Number.isFinite(r)||r<0?e:Math.floor(r)}class ut{constructor(t,e){this.source=t,this.kernel=e}source;kernel;get record(){return"function"==typeof this.source?this.source():this.source}static async all(){const t=pt(),e=await t.request($().sites());return(Array.isArray(e?.data)?e.data:[]).filter(t=>Boolean(t)&&"object"==typeof t).map(e=>new ut(e,t))}static async find(t){const e=pt(),r=null!=t&&""!==String(t)?String(t):e.siteRef(),n=e.snapshot().site;if(n&&(!t||String(n.uuid)===String(t)||String(n.id)===String(t)||String(n.domain)===String(t)||w(n)===String(t)))return new ut(n,e);const s=_(await e.request($().site(r)));return e.rememberSite(s),new ut(s,e)}static async findPage(t,e){return ht.find(t,e)}static async findMenu(t,e){return xt.find(t,e)}getName(){return new I(this.record.name)}getTitle(){const t=G(this.record.options,"seo_title")||G(this.record.options,"title");return new R(t||this.record.name)}getDomain(){return String(this.record.domain||"")}getLang(){return String(this.record.lang||"")}getUuid(){return String(this.record.uuid||"")}getOption(t){return new U(t,G(this.record.options,t))}getImage(t){const e=this.getOption(t),r=e.json(),n=null==r?e.toString().trim():r;if(null==n||""===n)return null;const s=D(n);return s?new Z(s,this.kernel):null}async findPage(t){return ht.find(t,this.ref())}async findMenu(t){return xt.find(t,this.ref())}async menus(){const t=this.kernel.snapshot().menus,e=Object.values(t).filter(Boolean);return e.length?e.map(t=>new xt(t,this.kernel)):((await this.kernel.request($().menus(this.ref()))).data??[]).map(t=>(this.kernel.rememberMenu(t),new xt(t,this.kernel)))}async pages(t={}){const e=new URLSearchParams,r={...t};null!=r.perPage&&null==r.per_page&&(r.per_page=r.perPage,delete r.perPage);for(const[o,a]of Object.entries(r))e.set(o,String(a));const n=e.toString()?`?${e.toString()}`:"",s=await this.kernel.request(`${$().pages(this.ref())}${n}`),i=(s.data??[]).map(t=>(this.kernel.rememberPage(t),new ht(t,this.kernel)));return ot(i,it(s,i.length))}async runAction(t){const e=String(t.uuid||"").trim();if(!e)throw new Error("Action uuid is required.");const r=String(this.record.domain||this.ref());return this.kernel.request($().action(r),{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({uuid:e,method:t.method||"GET",path:t.path||"",query:t.query||{},body:t.body||"",headers:t.headers||{},params:t.params||{},post:t.post||{}})})}raw(){return{...this.record}}ref(){return String(this.record.uuid||this.record.domain||this.record.id||this.kernel.siteRef())}}let lt=null;function pt(){if(!lt)throw new Error("Client is not installed.");return lt}class ht{constructor(t,e){this.source=t,this.kernel=e}source;kernel;get record(){return"function"==typeof this.source?this.source():this.source}setRecord(t){"function"!=typeof this.source?this.source=t:this.kernel.rememberPage(t)}static async findByUlid(t,e){return bt(t,e)}static async find(t,e){return bt(t,e)}static async search(t,e,r){const n=gt(),s=ft(n,e),i=new URLSearchParams;i.set("q",t),mt(i,r);const o=await n.request(`${$().search(s)}?${i.toString()}`),a=(Array.isArray(o?.data)?o.data:Array.isArray(o)?o:[]).map(t=>(n.rememberPage(t),new ht(t,n)));return ot(a,it(o,a.length))}getTitle(){return new P(this.record.title)}getSubtitle(){return new C(this.record.subtitle)}getSmallTitle(){return new M(this.record.smalltitle)}getSummary(){return new T(this.record.summary)}getContent(){return new O(this.record.content)}getSlug(){return String(this.record.slug||"")}getUrl(){return new N(this.record.full_url||(this.record.slug?`/${this.record.slug}`:"/"))}getUuid(){return String(this.record.uuid||this.record.ulid||"")}getId(){return String(this.record.id||this.getUuid())}getLayout(){return String(this.record.layout||"")}getDisplay(){return String(this.record.display||"")}getDisplayInMenu(){const t=this.record.display_in_menu;return null==t||""===t||!1!==t&&0!==t&&"0"!==t}getSortOrder(){const t=Number(this.record.sort_order??0);return Number.isFinite(t)?t:0}getLang(){const t=String(this.record.lang||"").trim();if(t)return t;const e=this.kernel.snapshot().site;return String(e?.lang||function(t){return t&&"object"==typeof t?String(t.lang||""):""}(this.record.site)||"")}getOption(t){const e=[G(this.record.options,t),this.kernel.snapshot().options[t],G(this.kernel.snapshot().site?.options,t),G(wt(this.record.site),t)];for(const r of e)if(yt(r))return new U(t,r);return new U(t,"")}getSeo(){const t=this.seoBag(),e=t=>null==t?"":String(t),r=t=>{const e=D(t);return e?new Z(e,this.kernel):null};return{title:new B(t.title??this.record.title),description:new q(t.description??this.record.summary),keywords:e(t.keywords),robots:e(t.robots),canonical:new N(t.canonical),ogTitle:e(t.og_title??t.title??this.record.title),ogDescription:e(t.og_description??t.description??this.record.summary),ogImage:r(t.og_image),ogType:e(t.og_type),ogUrl:new N(t.og_url||t.canonical),twitterCard:e(t.twitter_card),twitterTitle:e(t.twitter_title??t.og_title??t.title),twitterDescription:e(t.twitter_description??t.og_description??t.description),twitterImage:r(t.twitter_image||t.og_image),ldJson:St(t.ld_json),raw:{...t}}}get collectionItem(){const t=this.record.collectionItem;return t&&"object"==typeof t?t:{}}get collectionItems(){const t=this.record.collectionItems;return t&&"object"==typeof t?t:{}}get collectionGallery(){return t=this.record.collectionGallery,e=this.kernel,Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new rt(t,e)):[];var t,e}collectionImage(){return nt(this.collectionItem,this.kernel)}getAssets(){return new Y(tt(this.record.assets,this.kernel))}getGallery(t){const e=t.trim();if(!e)return new Y([]);const r=[];return tt(this.record.assets,this.kernel).forEach((t,n)=>{const s=t.memberships().find(t=>function(t,e){const r=e.trim().toLocaleLowerCase();return!!r&&(t.uuid.toLocaleLowerCase()===r||t.name.toLocaleLowerCase()===r)}(t,e));s&&r.push({asset:t,sort:s.sort_order,index:n})}),r.sort((t,e)=>t.sort-e.sort||t.index-e.index),new Y(r.map(t=>t.asset))}getGalleries(){const t=tt(this.record.assets,this.kernel);return this.galleryList(t).map(t=>({id:t.id,uuid:t.uuid,name:t.name,description:t.description,sort_order:t.sort_order,assets:this.getGallery(t.uuid||t.name)}))}async getChildren(t){const e=function(t){if(!Array.isArray(t))return[];const e=new Set(["options","assets"]),r=[];for(const n of t){const t=String(n).trim().toLowerCase();e.has(t)&&!r.includes(t)&&r.push(t)}return r}(t?.with),r=Array.isArray(this.record.children)?this.record.children:null;if(r&&function(t,e){return!e.length||t.every(t=>{if(!t||"object"!=typeof t)return!1;const r=t;if(e.includes("options")){const t=r.options;if(null==t||"object"!=typeof t)return!1}return!(e.includes("assets")&&!Array.isArray(r.assets))})}(r,e)){const e=function(t,e,r){const n=t.length;if(!e&&!r)return{items:t,meta:{currentPage:1,lastPage:1,perPage:Math.max(n,1),total:n}};const s=r&&r>0?Math.floor(r):Math.max(n,1),i=e&&e>0?Math.floor(e):1,o=Math.max(1,Math.ceil(n/s)),a=(i-1)*s;return{items:t.slice(a,a+s),meta:{currentPage:i,lastPage:o,perPage:s,total:n}}}(this.rowsToPages(r),t?.page,t?.perPage);return ot(e.items,e.meta)}const n=this.getUuid()||String(this.record.id??"");if(!n){const t=r?this.rowsToPages(r):[];return ot(t,it(null,t.length))}const s=new URLSearchParams;s.set("parent",n),e.length&&s.set("with",e.join(",")),mt(s,t);const i=await this.kernel.request(`${$().pages(this.siteRef())}?${s.toString()}`);return ot(this.rowsToPages(i.data??[]),it(i,(i.data??[]).length))}async getSiblings(){if(Array.isArray(this.record.siblings))return this.record.siblings.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new ht(t,this.kernel));const t=this.record.parent_id,e=this.siteRef();if(null==t||""===t){const t=await this.kernel.request(`${$().pages(e)}?parent=root`);return this.excludeSelf(t.data??[])}const r=await this.kernel.request(`${$().pages(e)}?parent=${encodeURIComponent(String(t))}`);return this.excludeSelf(r.data??[])}async getParent(){if(this.record.parent&&"object"==typeof this.record.parent)return new ht(this.record.parent,this.kernel);const t=this.record.parent_id;return null==t||""===t?null:bt(String(t),this.siteRef())}async getAncestors(){if(Array.isArray(this.record.ancestors))return this.rowsToPages(this.record.ancestors);const t=this.embeddedAncestors();if(t.length){const e=t[0],r=e.raw().parent_id;return null==r||""===r||0===r?t:[...await e.fetchAncestors(),...t]}return this.fetchAncestors()}async getSite(){if(this.record.site&&"object"==typeof this.record.site)return new ut(this.record.site,this.kernel);const t=this.kernel.snapshot().site;if(t&&(String(t.id)===String(this.record.site_id)||!this.record.site_id))return new ut(t,this.kernel);const e=this.record.site_id?String(this.record.site_id):this.kernel.siteRef(),r=_(await this.kernel.request($().site(e)));return this.kernel.rememberSite(r),new ut(r,this.kernel)}async load(){return await this.ensure(["content","options","assets","children"]),this}raw(){return{...this.record}}seoBag(){const t=this.record.seo&&"object"==typeof this.record.seo?this.record.seo:this.kernel.snapshot().seo;return t&&"object"==typeof t?{...t}:{}}galleryList(t){if(Array.isArray(this.record.galleries))return this.record.galleries.flatMap(t=>{const e=Q(t);if(!e)return[];const r=t&&"object"==typeof t?String(t.description??""):"";return[{...e,description:r}]});const e=new Map;for(const r of t)for(const t of r.memberships()){const r=(t.uuid||t.name).toLocaleLowerCase();r&&!e.has(r)&&e.set(r,{...t,description:""})}return[...e.values()]}siteRef(){return this.record.site&&"object"==typeof this.record.site?w(this.record.site)||this.kernel.siteRef():this.record.site_id?String(this.record.site_id):this.kernel.siteRef()}rowsToPages(t){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new ht(t,this.kernel)):[]}embeddedAncestors(){const t=[],e=new Set;let r=this.record.parent;for(;r&&"object"==typeof r&&t.length<12;){const n=r,s=String(n.uuid||n.id||"");if(!s||e.has(s))break;e.add(s),t.unshift(new ht(n,this.kernel)),r=n.parent}return t}async fetchAncestors(){const t=[],e=new Set;let r=await this.getParent();for(;r&&t.length<12;){const n=r.getUuid()||String(r.raw().id??"");if(!n||e.has(n))break;e.add(n),t.unshift(r),r=await r.getParent()}return t}excludeSelf(t){const e=y(this.record);return t.filter(t=>y(t)!==e).map(t=>new ht(t,this.kernel))}async ensure(t){if(!t.some(t=>void 0===this.record[t]))return;const e=this.getUuid()||this.getSlug()||String(this.record.id||"");if(!e)return;const r=_(await this.kernel.request($().page(this.siteRef(),e)));this.setRecord({...this.record,...r})}}let dt=null;function gt(){if(!dt)throw new Error("Client is not installed.");return dt}function ft(t,e){return null!=e&&""!==String(e)?String(e):t.siteRef()}function mt(t,e){e?.page&&e.page>0&&t.set("page",String(Math.floor(e.page))),e?.perPage&&e.perPage>0&&t.set("per_page",String(Math.floor(e.perPage)))}function yt(t){if(null==t)return!1;if("string"==typeof t){const e=t.trim();return""!==e&&"{}"!==e&&"[]"!==e}return Array.isArray(t)?t.length>0:"object"!=typeof t||Object.keys(t).length>0}function wt(t){if(t&&"object"==typeof t)return t.options}function St(t){if("string"==typeof t)return t;if(t&&"object"==typeof t)try{return JSON.stringify(t)}catch{return""}return""}async function bt(t,e){const r=gt(),n=ft(r,e),s=_(await r.request($().page(n,t)));return r.rememberPage(s),new ht(s,r)}class $t{constructor(t,e=null){this.record=t,this.kernel=e}record;kernel;getTitle(){return new W(this.record.title)}getUrl(){return new N(this.record.url)}getChildren(){return _t(this.record.children,this.kernel)}isCurrent(t){const e=this.getUrl().path();if(!e)return!1;if(t)return e===t.getUrl().path();const r=this.kernel??jt,n=r?.snapshot().page;return!(!r||!n)&&e===new ht(n,r).getUrl().path()}getPage(){const t=this.record.page;if(!t||"object"!=typeof t)return null;const e=this.kernel??jt;return e?new ht(t,e):null}raw(){return{...this.record}}}class xt{constructor(t,e){this.source=t,this.runtime=e}source;runtime;get record(){return"function"==typeof this.source?this.source():this.source}static async find(t,e){const r=function(){if(!jt)throw new Error("Client is not installed.");return jt}(),n=null!=e&&""!==String(e)?String(e):r.siteRef(),s=r.snapshot().menus,i=s[t]||Object.values(s).find(e=>!!e&&(String(e.uuid)===t||String(e.id)===t||String(e.name)===t||String(e.position)===t));if(i)return new xt(i,r);const o=_(await r.request($().menu(n,t)));return r.rememberMenu(o),new xt(o,r)}getName(){return new W(this.record.name)}getPosition(){return String(this.record.position||"")}getItems(){return _t(this.record.items,this.runtime)}raw(){return{...this.record}}}function _t(t,e=null){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new $t(t,e)):[]}let jt=null;class kt{snap={page:null,site:null,menus:{},locales:[],seo:null,options:{}};options;inflight=new Map;cache=new Map;constructor(t={}){this.options=t,t.page&&this.hydrate(t.page),dt=this,lt=this,jt=this}hydrate(t){return this.snap=g(this.snap,function(t){const e={page:null,site:null,menus:{},locales:[],seo:null,options:{}};if(!t||"object"!=typeof t)return e;const r=t,n=f(r.props)?r.props:r;e.page=m(n.page),e.site=m(n.site),e.seo=f(n.seo)?n.seo:null,e.options=f(n.options)?n.options:{},e.locales=Array.isArray(n.locales)?n.locales:[];const s=n.menus;if(f(s))for(const[i,o]of Object.entries(s))e.menus[i]=m(o);return e}(t)),this.snap}snapshot(){return this.snap}apiBase(){return function(t){if(t)return String(t).replace(/\/+$/,"");const e=x();return e.apiBase?String(e.apiBase).replace(/\/+$/,""):function(){if("undefined"==typeof location)return"";const t=String(location.origin||"").replace(/\/+$/,"");if(t&&"null"!==t)return t;const e=location.hostname||"";return e?`${location.protocol}//${e}`:""}()}(this.options.apiBase)}siteBase(){return function(t){if(t)return String(t).replace(/\/+$/,"");const e=x();return e.siteBase?String(e.siteBase).replace(/\/+$/,""):"undefined"!=typeof location?location.origin:""}(this.options.siteBase)}siteRef(){return null!=this.options.site&&""!==String(this.options.site)?String(this.options.site):w(this.snap.site)}async request(t,e={}){const r=String(e.method||"GET").toUpperCase(),n=`${r} ${t}`;if("GET"===r&&this.cache.has(n))return this.cache.get(n);if("GET"===r){const t=this.inflight.get(n);if(t)return t}const s=this.apiBase();if(!s)throw new Error("Remote origin is not configured.");const i=async function(t,e,r={}){const{fetchImpl:n,...s}=r,i=e.startsWith("http")?e:b(t,e),o=n??fetch,a=new Headers(s.headers);a.has("Accept")||a.set("Accept","application/json");const c=await o(i,{...s,headers:a}),u=await c.text();let l=null;if(u)try{l=JSON.parse(u)}catch{l={message:u}}if(!c.ok){const t=new Error(`Request failed (${c.status})`);throw t.status=c.status,t.body=l,t}return l}(s,t,{...e,fetchImpl:this.options.fetch}).then(t=>("GET"===r&&this.cache.set(n,t),t));return"GET"===r&&(this.inflight.set(n,i),i.finally(()=>{this.inflight.delete(n)}).catch(()=>{})),i}rememberPage(t){const e=this.snap.page;e&&String(e.id)===String(t.id)&&(this.snap=g(this.snap,{page:{...e,...t}}))}rememberSite(t){this.snap=g(this.snap,{site:{...this.snap.site??{},...t}})}rememberMenu(t){const e=String(t.position||t.uuid||t.id||t.name||"menu");this.snap=g(this.snap,{menus:{[e]:t}})}}let At=null;function vt(t={}){return At=new kt(t),At}function Pt(){return At||(At=new kt),At}const Ct=Symbol.for("miro.client");function Mt(){return t.inject(Ct,null)??Pt()}function Tt(t={}){return{install(e,r={}){const n=vt({...t,...r});e.provide(Ct,n),e.component("MiroText",d),function(t){import("@inertiajs/vue3").then(e=>{const r=e.router;r?.page&&t.hydrate(r.page),r?.on?.("success",e=>{const r=e?.detail?.page;r&&t.hydrate(r)}),r?.on?.("navigate",e=>{const r=e?.detail?.page;r&&t.hydrate(r)})}).catch(()=>{})}(n)}}}const Ot=Tt();class Rt{constructor(t){this.kernel=t}kernel;all(){return function(t,e=function(){return globalThis}()){const r=Array.isArray(t)?t.flatMap(t=>function(t){if(!t||"object"!=typeof t)return[];const e=t,r=It(String(e.lang??""));return r?[{lang:r,domain:Nt(String(e.domain??"")),url:String(e.url??"").trim()}]:[]}(t)):[];return r.length?r.flatMap(t=>{const r=Ut(t.url||function(t,e){const r=e[`locale_${t}_baseurl`];return"string"==typeof r?r.trim():""}(t.lang,e)||t.domain);return t.lang&&r?[{lang:t.lang,domain:t.domain||Nt(r),url:r}]:[]}):function(t){const e=[];for(const r of Object.keys(t)){const n=/^locale_([a-z]+)_baseurl$/.exec(r);if(!n)continue;const s=Ut(String(t[r]??""));s&&e.push({lang:n[1],domain:Nt(s),url:s})}return e}(e)}(this.kernel.snapshot().locales)}current(){return It(String(this.kernel.snapshot().site?.lang||""))}url(t){const e=It(t),r=this.all().find(t=>t.lang===e);return r?.url??""}}function It(t){return(t.trim().toLowerCase().replaceAll("_","-").split("-")[0]??"").replace(/[^a-z]/g,"")}function Ut(t){const e=t.trim();return e?(/^https?:\/\//i.test(e)?e:`https://${e.replace(/^\/+/,"")}`).replace(/\/+$/,""):""}function Nt(t){return t.trim().replace(/^https?:\/\//i,"").replace(/\/.*$/,"")}function Wt(t){return`mc_${(String(t??"").trim().split("/").pop()??"").replace(/^@/,"").replace(/[^A-Za-z0-9]+/g,"_").replace(/^_+|_+$/g,"").toUpperCase()}`}function Lt(t){if("undefined"==typeof window||""===t)return"";const e=window.__MIRO_WEB_PLUGINS__;if(!Array.isArray(e))return"";for(const r of e){const e=String(r??"").trim().toLowerCase(),n=e.lastIndexOf("/");if(n<=0)continue;const s=e.slice(0,n),i=e.slice(n+1);if(""!==s&&(i===t||Bt(i)===t))return s}return""}function Bt(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[^A-Za-z0-9]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()}function qt(t){if("undefined"==typeof window)return{};const e=window[t];return e&&"object"==typeof e?e:{}}function Et(){const t=Mt(),e=function(){try{const t=globalThis.__INERTIA_PAGE__;if(t?.props)return t.props}catch{}return function(){if("undefined"==typeof document)return null;const t=document.querySelector("[data-page]")?.getAttribute("data-page");if(!t)return null;try{return JSON.parse(t).props??null}catch{return null}}()}();return e&&t.hydrate(e),t}function Gt(){const t=Et();return Dt(t),new ht(()=>t.snapshot().page??{},t)}function Dt(e){try{const r=function(){try{return zt??null}catch{return null}}();if(!r)return;const n=r.usePage();e.hydrate(t.unref(n))}catch{}}let zt=null;import("@inertiajs/vue3").then(t=>{zt=t}).catch(()=>{zt=null});const Jt=Ot;exports.Asset=Z,exports.AssetName=L,exports.CollectionCard=rt,exports.Gallery=Y,exports.Locales=Rt,exports.Menu=xt,exports.MenuItem=$t,exports.MenuTitle=W,exports.Miro=Ot,exports.MiroText=d,exports.OptionValue=U,exports.Page=ht,exports.PageContent=O,exports.PageSmallTitle=M,exports.PageSubtitle=C,exports.PageSummary=T,exports.PageTitle=P,exports.RICH_COLORS=e,exports.RICH_FONTS=r,exports.SDK_KEY=Ct,exports.SeoDescription=q,exports.SeoTitle=B,exports.Site=ut,exports.SiteName=I,exports.SiteTitle=R,exports.TextValue=v,exports.UrlValue=N,exports.createMiro=Tt,exports.createRuntime=vt,exports.default=Jt,exports.getRuntime=Pt,exports.parseRichText=o,exports.plainText=c,exports.pluginWindowKey=Wt,exports.useKernel=Mt,exports.useMiroAssets=function(){return Gt().getAssets()},exports.useMiroConfig=function(){const e=Mt();return{apiBase:t.computed(()=>e.apiBase()),siteBase:t.computed(()=>e.siteBase()),siteRef:t.computed(()=>e.siteRef())}},exports.useMiroLocales=function(){const t=Et();return Dt(t),new Rt(t)},exports.useMiroMenu=function(t="topbar"){const e=Et();return Dt(e),new xt(()=>e.snapshot().menus[t]??{position:t,items:[]},e)},exports.useMiroPage=Gt,exports.useMiroSite=function(){const t=Et();return Dt(t),new ut(()=>t.snapshot().site??{},t)},exports.usePlugin=function(t){return function(t,e){const r=Wt(t),n=function(t){const e=String(t??"").trim();if(e.includes("/")){const[t,...r]=e.split("/");return{vendor:t||"miroart",slug:Bt(r.join("/")||e)}}const r=Bt(e);return{vendor:Lt(r)||"miroart",slug:r}}(t);return new Proxy({name:t,key:r,ready:async()=>async function(t){const e=Date.now();for(;Date.now()-e<4e3;){const e=qt(t);if(Object.keys(e).length)return e;await new Promise(t=>setTimeout(t,50))}return qt(t)}(r),api:()=>qt(r),call:(t,...e)=>{const n=qt(r),s=n[t];if("function"!=typeof s)throw new Error(`Missing plugin method: ${t}`);return s.apply(n,e)},request:async(t="/",r={})=>{const s=$().plugins(n.vendor,n.slug,t||"/"),i=new Headers(r.headers);let o=r.body;return void 0!==r.json&&(o=JSON.stringify(r.json)),_(await e.request(s,{...r,headers:i,body:o}))}},{get(t,e,n){if(e in t)return Reflect.get(t,e,n);if("then"===e||e===Symbol.toStringTag)return;const s=qt(r),i=s[String(e)];return"function"==typeof i?i.bind(s):i},has:(t,e)=>e in t||e in qt(r)})}(t,Mt())};
1
+ "use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty,Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),e=["primary","secondary","accent","neutral","base-100","base-content","info","success","warning","error"],r=["sans","serif"],n=/\\(\[\/?(?:b|i|u|s|c|f)(?:=[a-z0-9-]+)?\])|\[(\/?)(b|i|u|s|c|f)(?:=([a-z0-9-]+))?\]/g;function i(t,n){return"c"===t?e.includes(n??""):"f"===t?r.includes(n??""):void 0===n}function s(t,e){""!==e&&e.split(/\r?\n/).forEach((e,r)=>{if(r>0&&t.push({type:"br"}),""===e)return;const n=t[t.length-1];"text"===n?.type?n.value+=e:t.push({type:"text",value:e})})}function o(t){const e=String(t??""),r=[],o=[],a=()=>o[o.length-1]?.children??r,c=()=>{var t,e;t=o.pop(),e=a(),0!==t.children.length&&("c"===t.tag?e.push({type:"c",value:t.value,children:t.children}):"f"===t.tag?e.push({type:"f",value:t.value,children:t.children}):e.push({type:t.tag,children:t.children}))};let u,l=0;for(n.lastIndex=0;null!==(u=n.exec(e));){s(a(),e.slice(l,u.index)),l=n.lastIndex;const[t,r,p,h,d]=u;if(void 0===r){if("/"===p){const e=void 0===d?o.map(t=>t.tag).lastIndexOf(h):-1;if(-1===e){s(a(),t);continue}for(;o.length>e;)c();continue}!i(h,d)||o.length>=8?s(a(),t):o.push({tag:h,value:d??null,children:[]})}else s(a(),r)}for(s(a(),e.slice(l));o.length>0;)c();return r}function a(t,e){for(const r of t)"text"===r.type?e.push(r.value):"br"===r.type?e.push("\n"):a(r.children,e)}function c(t){const e=String(t??"");if(!e.includes("["))return e;const r=[];return a(o(e),r),r.join("")}function u(t){return null==t?"":"string"==typeof t?t:"number"==typeof t||"boolean"==typeof t?String(t):""}function l(t){const e=u(t);if(!e)return"";if("undefined"!=typeof document){const t=document.createElement("textarea");return t.innerHTML=e,t.value}return e.replace(/&#(\d+);/g,(t,e)=>String.fromCharCode(Number(e))).replace(/&#x([0-9a-f]+);/gi,(t,e)=>String.fromCharCode(parseInt(e,16))).replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">")}function p(t){return c(l(t)).replace(/<script[\s\S]*?>[\s\S]*?<\/script>/gi," ").replace(/<style[\s\S]*?>[\s\S]*?<\/style>/gi," ").replace(/<[^>]+>/g," ").replace(/\s+/g," ").trim()}class h extends String{kind;extra;constructor(t,e,r={}){super(l(e)),this.kind=t,this.extra=r,Object.setPrototypeOf(this,new.target.prototype)}toString(){return String.prototype.toString.call(this)}valueOf(){return String.prototype.valueOf.call(this)}raw(){return this.toString()}decode(){return l(this.toString())}cleanContent(){return p(this.toString())}stripHtml(){return this.cleanContent()}plain(){return c(this.toString())}excerpt(t=160){const e=this.cleanContent();return e.length<=t?e:`${e.slice(0,Math.max(0,t-1)).trimEnd()}…`}firstParagraph(){return function(t){const e=l(t),r=e.match(/<p\b[^>]*>([\s\S]*?)<\/p>/i);return p(r?r[1]:e)}(this.toString())}isEmpty(){return""===this.cleanContent()}json(){const t=this.toString().trim();if(!t)return null;try{return JSON.parse(t)}catch{return null}}bool(){const t=this.toString().trim().toLowerCase();return"1"===t||"true"===t||"yes"===t||"on"===t}number(){const t=Number(this.toString().trim());return Number.isFinite(t)?t:null}}class d extends h{constructor(t){super("PageTitle",t)}}class g extends h{constructor(t){super("PageSubtitle",t)}}class f extends h{constructor(t){super("PageSmallTitle",t)}}class m extends h{constructor(t){super("PageSummary",t)}}class y extends h{constructor(t){super("PageContent",t)}html(){return this.toString()}}class w extends h{constructor(t){super("SiteTitle",t)}}class S extends h{constructor(t){super("SiteName",t)}}class b extends h{key;structured;constructor(t,e){const r=A(e);super("OptionValue",r.text,{key:t}),this.key=t,this.structured=r.structured}json(){return void 0!==this.structured?this.structured:super.json()}present(){return!this.isEmpty()}}class $ extends h{constructor(t){super("UrlValue",t)}path(){const t=this.toString().trim();if(!t)return"/";try{if(/^https?:\/\//i.test(t))return new URL(t).pathname.replace(/\/+$/,"")||"/"}catch{}return(t.startsWith("/")?t:`/${t}`).replace(/\/+$/,"")||"/"}href(t=""){const e=this.path();return!t||/^https?:\/\//i.test(e)?e:`${String(t).replace(/\/+$/,"")}${e}`}}class k extends h{constructor(t){super("MenuTitle",t)}}class _ extends h{constructor(t){super("AssetName",t)}}class x extends h{constructor(t){super("SeoTitle",t)}}class j extends h{constructor(t){super("SeoDescription",t)}}function A(t){if(null==t)return{text:""};if("boolean"==typeof t||"number"==typeof t)return{text:String(t)};if("string"==typeof t){const e=t.trim();if(""===e||"[]"===e||"{}"===e)return{text:""};if(e.startsWith("{")&&e.endsWith("}")||e.startsWith("[")&&e.endsWith("]")||e.startsWith('"')&&e.endsWith('"'))try{return A(JSON.parse(e))}catch{return{text:l(t)}}return{text:l(t)}}return Array.isArray(t)?{text:JSON.stringify(t),structured:t}:"object"==typeof t?function(t){return"value"in t&&Object.keys(t).every(t=>"value"===t||"key"===t||"id"===t||"active"===t)}(t)?A(t.value):{text:JSON.stringify(t),structured:t}:{text:u(t)}}function v(t,e){if(!t)return"";if(Array.isArray(t)){const r=t.find(t=>t&&"object"==typeof t&&t.key===e);return r&&"object"==typeof r?r.value:""}return"object"==typeof t?t[e]:""}function P(t){return String.fromCharCode(...t.map(t=>23^t))}function C(t,e){const r=String(t||"").replace(/\/+$/,""),n=e.startsWith("/")?e:`/${e}`;return r?`${r}${n}`:n}function O(){const t=P([56,118,103,126]),e=P([97,38]),r=P([100,126,99,114,100]),n=P([103,118,112,114,100]),i=P([100,114,118,101,116,127]),s=P([122,114,121,98,100]),o=P([122,114,115,126,118]),a=P([103,123,98,112,126,121,100]),c=P([118,116,99,126,120,121,100]);return{sites:()=>C("",`${t}/${e}/${r}`),site:n=>C("",`${t}/${e}/${r}/${encodeURIComponent(n)}`),pages:i=>C("",`${t}/${e}/${r}/${encodeURIComponent(i)}/${n}`),page:(i,s)=>C("",`${t}/${e}/${r}/${encodeURIComponent(i)}/${n}/${s.split("/").map(t=>encodeURIComponent(t)).join("/")}`),search:s=>C("",`${t}/${e}/${r}/${encodeURIComponent(s)}/${n}/${i}`),menus:n=>C("",`${t}/${e}/${r}/${encodeURIComponent(n)}/${s}`),menu:(n,i)=>C("",`${t}/${e}/${r}/${encodeURIComponent(n)}/${s}/${encodeURIComponent(i)}`),media:e=>C("",`${t}/${o}/${encodeURIComponent(e)}`),action:e=>C("",`${t}/${c}/${encodeURIComponent(e)}`),plugins:(e,r,n="")=>{const i=`${t}/${a}/${encodeURIComponent(e)}/${encodeURIComponent(r)}`;return n&&"/"!==n?`${i}${n.startsWith("/")?n:`/${n}`}`:i}}}function M(t){if("string"==typeof t){const e=t.trim();return e?N(e)?{uuid:e}:{url:e,path:e}:null}if(!t||"object"!=typeof t||Array.isArray(t))return null;const e=t,r=U(e.source),n=T(e.url,e.preview_url,e.path,e.src,r?.url,r?.preview_url,r?.path),i=T(e.uuid,r?.uuid);if(n||i&&N(i))return e;const s=T(e.value);return s?M(s):null}function T(...t){for(const e of t)if("string"==typeof e&&""!==e.trim())return e.trim();return""}function R(t){return"string"==typeof t?t.trim():""}function U(t){return!t||"object"!=typeof t||Array.isArray(t)?null:t}function I(t){return t.startsWith("/media/")||t.startsWith("/_images/")||t.startsWith("/api/media/")||t.startsWith("/branding-assets/")||t.startsWith("/storage/")}function N(t){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t)}const W=[{mark:"1_8",width:256},{mark:"1_4",width:512},{mark:"1_2",width:1024},{mark:"2_3",width:1400}];class E{constructor(t,e){this.record=t,this.runtime=e}record;runtime;getUuid(){return String(this.record.uuid||this.record.id||"")}getName(){return new _(this.record.name)}getAlt(){return R(this.record.alt)}getCaption(){return R(this.record.caption)}getGallery(){return this.memberships()[0]??null}galleryUuid(){return this.memberships()[0]?.uuid??""}galleryName(){return this.memberships()[0]?.name??""}memberships(){const t=this.record.galleries;if(Array.isArray(t)&&t.length>0)return t.map(t=>B(t)).filter(t=>null!==t);const e=String(this.record.gallery_uuid??"").trim(),r=String(this.record.gallery_name??"").trim();if(!e&&!r)return[];const n=this.record.gallery_id;return[{id:"number"==typeof n||"string"==typeof n?n:null,uuid:e,name:r,sort_order:q(this.record.gallery_sort_order)}]}getMime(){const t=U(this.record.source);return String(this.record.mime_type||t?.mime_type||"")}getSize(){const t=U(this.record.source),e=Number(this.record.size??t?.size??0);return Number.isFinite(e)?e:0}getType(){const t=R(this.record.type);if(t)return t;const e=this.getMime();return e.startsWith("image/")?"image":e.startsWith("video/")?"video":"application/pdf"===e?"pdf":""}getSortOrder(){const t=Number(this.record.sort_order??0);return Number.isFinite(t)?t:0}isImage(){return!!this.getMime().startsWith("image/")||/\.(jpe?g|png|gif|webp|svg)(\?|$)/i.test(this.urlString())}url(){return new $(this.urlString())}srcset(){const t=this.urlString();if(!t||/\.svg([?#]|$)/i.test(t)||/^https?:\/\//i.test(t)||t.startsWith("//"))return"";if(!/\.webp([?#]|$)/i.test(t)||/\.(?:1_16|1_8|1_4|1_2|2_3)\.webp([?#]|$)/i.test(t))return"";const e=W.map(({mark:e,width:r})=>`${t.replace(/\.webp([?#].*)?$/i,`.${e}.webp$1`)} ${r}w`);return e.push(`${t} 2048w`),e.join(", ")}raw(){return{...this.record}}urlString(){const t=U(this.record.source),e=T(this.record.uuid,t?.uuid),r=T(this.record.disk,t?.disk);let n=T(this.record.url,this.record.preview_url,this.record.path,this.record.src,t?.url,t?.preview_url,t?.path);if(e&&N(e)&&n&&function(t,e){return!!(/\/project-storage\//i.test(r=t)||/\/editor\/project-file/i.test(r)||/cms\.miroart\.pl/i.test(r)&&/\/(?:project-storage|storage)\//i.test(r))||"project_public"===e&&!I(t)&&!/^https?:\/\//i.test(t)&&!t.startsWith("//");var r}(n,r))return this.mediaUrl(e);if(!n)return e&&N(e)?this.mediaUrl(e):"";if(!0===globalThis.isSsg){if(n.startsWith("/_images/")||n.startsWith("_images/"))return n.startsWith("/")?n:`/${n}`;const e=function(t){const e=t.match(/[?&]path=([^&]+)/i);if(e)try{const t=decodeURIComponent(e[1].replace(/\+/g," ")).split(/[/\\]/).pop()||"";if(t&&"project-file"!==t.toLowerCase())return t.trim()}catch{}return(t.split("#")[0].split("?")[0].split(/[/\\]/).pop()||"").trim()}(T(t?.path,this.record.path,n)),r=/\.(jpe?g|png|gif|webp|svg)$/i.test(i=e)?/\.svg$/i.test(i)?`/_images/${i}`:`/_images/${i.replace(/\.(jpe?g|png|gif|webp)$/i,".webp")}`:null;if(r)return r}var i;if(/^https?:\/\//i.test(n)||n.startsWith("//"))return n;if(n.startsWith("_images/"))return`/${n}`;if(I(n))return n;n.includes("/")||n.includes("\\")||N(n)||(n=`images/${n}`);const s=n.startsWith("/")?n:`/${n}`;return I(s)||s.startsWith("/project-storage/")?s:`/storage${s}`}mediaUrl(t){const e=O().media(t),r=this.runtime.apiBase();return r?C(r,e):e}}class L{constructor(t){this.items=t}items;all(){return this.items.slice()}first(){return this.items[0]??null}extra(){return this.items.slice(1)}hero(){return this.first()}urls(){return this.items.map(t=>t.url())}isEmpty(){return 0===this.items.length}count(){return this.items.length}[Symbol.iterator](){return this.items[Symbol.iterator]()}}function B(t){if(!t||"object"!=typeof t)return null;const e=t,r=String(e.uuid??"").trim(),n=String(e.name??"").trim();if(!r&&!n)return null;const i=e.id;return{id:"number"==typeof i||"string"==typeof i?i:null,uuid:r,name:n,sort_order:q(e.sort_order)}}function q(t){const e=Number(t??0);return Number.isFinite(e)?e:0}function G(t,e){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new E(t,e)):[]}function z(){if("undefined"==typeof globalThis)return{};const t=globalThis.MiroConfig;return t&&"object"==typeof t?t:{}}function F(t){return t&&"object"==typeof t&&"data"in t?t.data:t}function D(t,e){return{page:void 0!==e.page?e.page:t.page,site:void 0!==e.site?e.site:t.site,menus:e.menus?{...t.menus,...e.menus}:{...t.menus},locales:e.locales??t.locales,seo:void 0!==e.seo?e.seo:t.seo,options:e.options?{...t.options,...e.options}:{...t.options},editing:e.editing??t.editing}}function J(t){return Boolean(t)&&"object"==typeof t&&!Array.isArray(t)}function H(t){return J(t)?t:null}function V(t){return t?String(t.uuid||t.ulid||t.id||t.slug||t.full_url||""):""}function K(t){return t?String(t.uuid||t.domain||t.id||""):""}const Z=new Set(["id","uuid","created_at","updated_at"]);class Y{constructor(t,e){this.row=t,this.kernel=e}row;kernel;getHref(){return new $(this.row.href)}getTitle(){return String(this.row.title??"")}item(){const t=this.row.item;return t&&"object"==typeof t?t:{}}image(){return Q(this.item(),this.kernel)}}function Q(t,e){if(!t||"object"!=typeof t)return null;for(const[r,n]of Object.entries(t)){if(Z.has(r)||"string"!=typeof n||!X(n))continue;const t=M(n);if(t)return new E(t,e)}return null}function X(t){const e=t.trim();return!!e&&(!!(e.startsWith("/media/")||e.startsWith("/_images/")||e.startsWith("_images/")||e.startsWith("/api/media/")||e.startsWith("/branding-assets/"))||/\.(jpe?g|png|gif|webp|svg)(\?|#|$)/i.test(e))}function tt(t,e){const r=t&&"object"==typeof t?t.meta:null,n=r&&"object"==typeof r?r:{};return{currentPage:rt(n.current_page,1),lastPage:rt(n.last_page,1),perPage:rt(n.per_page,Math.max(e,1)),total:nt(n.total,e)}}function et(t,e){return Object.assign(t,{meta:e})}function rt(t,e){const r=Number(t);return!Number.isFinite(r)||r<1?e:Math.floor(r)}function nt(t,e){if(null==t||""===t)return e;const r=Number(t);return!Number.isFinite(r)||r<0?e:Math.floor(r)}class it{constructor(t,e){this.source=t,this.kernel=e}source;kernel;get record(){return"function"==typeof this.source?this.source():this.source}static async all(){const t=ot(),e=await t.request(O().sites());return(Array.isArray(e?.data)?e.data:[]).filter(t=>Boolean(t)&&"object"==typeof t).map(e=>new it(e,t))}static async find(t){const e=ot(),r=null!=t&&""!==String(t)?String(t):e.siteRef(),n=e.snapshot().site;if(n&&(!t||String(n.uuid)===String(t)||String(n.id)===String(t)||String(n.domain)===String(t)||K(n)===String(t)))return new it(n,e);const i=F(await e.request(O().site(r)));return e.rememberSite(i),new it(i,e)}static async findPage(t,e){return at.find(t,e)}static async findMenu(t,e){return yt.find(t,e)}getName(){return new S(this.record.name)}getTitle(){const t=v(this.record.options,"seo_title")||v(this.record.options,"title");return new w(t||this.record.name)}getDomain(){return String(this.record.domain||"")}getLang(){return String(this.record.lang||"")}getUuid(){return String(this.record.uuid||"")}getOption(t){return new b(t,v(this.record.options,t))}getImage(t){const e=this.getOption(t),r=e.json(),n=null==r?e.toString().trim():r;if(null==n||""===n)return null;const i=M(n);return i?new E(i,this.kernel):null}async findPage(t){return at.find(t,this.ref())}async findMenu(t){return yt.find(t,this.ref())}async menus(){const t=this.kernel.snapshot().menus,e=Object.values(t).filter(Boolean);return e.length?e.map(t=>new yt(t,this.kernel)):((await this.kernel.request(O().menus(this.ref()))).data??[]).map(t=>(this.kernel.rememberMenu(t),new yt(t,this.kernel)))}async pages(t={}){const e=new URLSearchParams,r={...t};null!=r.perPage&&null==r.per_page&&(r.per_page=r.perPage,delete r.perPage);for(const[o,a]of Object.entries(r))e.set(o,String(a));const n=e.toString()?`?${e.toString()}`:"",i=await this.kernel.request(`${O().pages(this.ref())}${n}`),s=(i.data??[]).map(t=>(this.kernel.rememberPage(t),new at(t,this.kernel)));return et(s,tt(i,s.length))}async runAction(t){const e=String(t.uuid||"").trim();if(!e)throw new Error("Action uuid is required.");const r=String(this.record.domain||this.ref());return this.kernel.request(O().action(r),{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({uuid:e,method:t.method||"GET",path:t.path||"",query:t.query||{},body:t.body||"",headers:t.headers||{},params:t.params||{},post:t.post||{}})})}raw(){return{...this.record}}ref(){return String(this.record.uuid||this.record.domain||this.record.id||this.kernel.siteRef())}}let st=null;function ot(){if(!st)throw new Error("Client is not installed.");return st}class at{constructor(t,e){this.source=t,this.kernel=e}source;kernel;get record(){return"function"==typeof this.source?this.source():this.source}setRecord(t){"function"!=typeof this.source?this.source=t:this.kernel.rememberPage(t)}static async findByUlid(t,e){return ft(t,e)}static async find(t,e){return ft(t,e)}static async search(t,e,r){const n=ut(),i=lt(n,e),s=new URLSearchParams;s.set("q",t),pt(s,r);const o=await n.request(`${O().search(i)}?${s.toString()}`),a=(Array.isArray(o?.data)?o.data:Array.isArray(o)?o:[]).map(t=>(n.rememberPage(t),new at(t,n)));return et(a,tt(o,a.length))}getTitle(){return new d(this.record.title)}getSubtitle(){return new g(this.record.subtitle)}getSmallTitle(){return new f(this.record.smalltitle)}getSummary(){return new m(this.record.summary)}getContent(){return new y(this.record.content)}getSlug(){return String(this.record.slug||"")}getUrl(){return new $(this.record.full_url||(this.record.slug?`/${this.record.slug}`:"/"))}getUuid(){return String(this.record.uuid||this.record.ulid||"")}getId(){return String(this.record.id||this.getUuid())}getLayout(){return String(this.record.layout||"")}getDisplay(){return String(this.record.display||"")}getDisplayInMenu(){const t=this.record.display_in_menu;return null==t||""===t||!1!==t&&0!==t&&"0"!==t}getSortOrder(){const t=Number(this.record.sort_order??0);return Number.isFinite(t)?t:0}getLang(){const t=String(this.record.lang||"").trim();if(t)return t;const e=this.kernel.snapshot().site;return String(e?.lang||function(t){return t&&"object"==typeof t?String(t.lang||""):""}(this.record.site)||"")}getOption(t){const e=[v(this.record.options,t),this.kernel.snapshot().options[t],v(this.kernel.snapshot().site?.options,t),v(dt(this.record.site),t)];for(const r of e)if(ht(r))return new b(t,r);return new b(t,"")}getSeo(){const t=this.seoBag(),e=t=>null==t?"":String(t),r=t=>{const e=M(t);return e?new E(e,this.kernel):null};return{title:new x(t.title??this.record.title),description:new j(t.description??this.record.summary),keywords:e(t.keywords),robots:e(t.robots),canonical:new $(t.canonical),ogTitle:e(t.og_title??t.title??this.record.title),ogDescription:e(t.og_description??t.description??this.record.summary),ogImage:r(t.og_image),ogType:e(t.og_type),ogUrl:new $(t.og_url||t.canonical),twitterCard:e(t.twitter_card),twitterTitle:e(t.twitter_title??t.og_title??t.title),twitterDescription:e(t.twitter_description??t.og_description??t.description),twitterImage:r(t.twitter_image||t.og_image),ldJson:gt(t.ld_json),raw:{...t}}}get collectionItem(){const t=this.record.collectionItem;return t&&"object"==typeof t?t:{}}get collectionItems(){const t=this.record.collectionItems;return t&&"object"==typeof t?t:{}}get collectionGallery(){return t=this.record.collectionGallery,e=this.kernel,Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new Y(t,e)):[];var t,e}collectionImage(){return Q(this.collectionItem,this.kernel)}getAssets(){return new L(G(this.record.assets,this.kernel))}getGallery(t){const e=t.trim();if(!e)return new L([]);const r=[];return G(this.record.assets,this.kernel).forEach((t,n)=>{const i=t.memberships().find(t=>function(t,e){const r=e.trim().toLocaleLowerCase();return!!r&&(t.uuid.toLocaleLowerCase()===r||t.name.toLocaleLowerCase()===r)}(t,e));i&&r.push({asset:t,sort:i.sort_order,index:n})}),r.sort((t,e)=>t.sort-e.sort||t.index-e.index),new L(r.map(t=>t.asset))}getGalleries(){const t=G(this.record.assets,this.kernel);return this.galleryList(t).map(t=>({id:t.id,uuid:t.uuid,name:t.name,description:t.description,sort_order:t.sort_order,assets:this.getGallery(t.uuid||t.name)}))}async getChildren(t){const e=function(t){if(!Array.isArray(t))return[];const e=new Set(["options","assets"]),r=[];for(const n of t){const t=String(n).trim().toLowerCase();e.has(t)&&!r.includes(t)&&r.push(t)}return r}(t?.with),r=Array.isArray(this.record.children)?this.record.children:null;if(r&&function(t,e){return!e.length||t.every(t=>{if(!t||"object"!=typeof t)return!1;const r=t;if(e.includes("options")){const t=r.options;if(null==t||"object"!=typeof t)return!1}return!(e.includes("assets")&&!Array.isArray(r.assets))})}(r,e)){const e=function(t,e,r){const n=t.length;if(!e&&!r)return{items:t,meta:{currentPage:1,lastPage:1,perPage:Math.max(n,1),total:n}};const i=r&&r>0?Math.floor(r):Math.max(n,1),s=e&&e>0?Math.floor(e):1,o=Math.max(1,Math.ceil(n/i)),a=(s-1)*i;return{items:t.slice(a,a+i),meta:{currentPage:s,lastPage:o,perPage:i,total:n}}}(this.rowsToPages(r),t?.page,t?.perPage);return et(e.items,e.meta)}const n=this.getUuid()||String(this.record.id??"");if(!n){const t=r?this.rowsToPages(r):[];return et(t,tt(null,t.length))}const i=new URLSearchParams;i.set("parent",n),e.length&&i.set("with",e.join(",")),pt(i,t);const s=await this.kernel.request(`${O().pages(this.siteRef())}?${i.toString()}`);return et(this.rowsToPages(s.data??[]),tt(s,(s.data??[]).length))}async getSiblings(){if(Array.isArray(this.record.siblings))return this.record.siblings.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new at(t,this.kernel));const t=this.record.parent_id,e=this.siteRef();if(null==t||""===t){const t=await this.kernel.request(`${O().pages(e)}?parent=root`);return this.excludeSelf(t.data??[])}const r=await this.kernel.request(`${O().pages(e)}?parent=${encodeURIComponent(String(t))}`);return this.excludeSelf(r.data??[])}async getParent(){if(this.record.parent&&"object"==typeof this.record.parent)return new at(this.record.parent,this.kernel);const t=this.record.parent_id;return null==t||""===t?null:ft(String(t),this.siteRef())}async getAncestors(){if(Array.isArray(this.record.ancestors))return this.rowsToPages(this.record.ancestors);const t=this.embeddedAncestors();if(t.length){const e=t[0],r=e.raw().parent_id;return null==r||""===r||0===r?t:[...await e.fetchAncestors(),...t]}return this.fetchAncestors()}async getSite(){if(this.record.site&&"object"==typeof this.record.site)return new it(this.record.site,this.kernel);const t=this.kernel.snapshot().site;if(t&&(String(t.id)===String(this.record.site_id)||!this.record.site_id))return new it(t,this.kernel);const e=this.record.site_id?String(this.record.site_id):this.kernel.siteRef(),r=F(await this.kernel.request(O().site(e)));return this.kernel.rememberSite(r),new it(r,this.kernel)}async load(){return await this.ensure(["content","options","assets","children"]),this}raw(){return{...this.record}}seoBag(){const t=this.record.seo&&"object"==typeof this.record.seo?this.record.seo:this.kernel.snapshot().seo;return t&&"object"==typeof t?{...t}:{}}galleryList(t){if(Array.isArray(this.record.galleries))return this.record.galleries.flatMap(t=>{const e=B(t);if(!e)return[];const r=t&&"object"==typeof t?String(t.description??""):"";return[{...e,description:r}]});const e=new Map;for(const r of t)for(const t of r.memberships()){const r=(t.uuid||t.name).toLocaleLowerCase();r&&!e.has(r)&&e.set(r,{...t,description:""})}return[...e.values()]}siteRef(){return this.record.site&&"object"==typeof this.record.site?K(this.record.site)||this.kernel.siteRef():this.record.site_id?String(this.record.site_id):this.kernel.siteRef()}rowsToPages(t){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new at(t,this.kernel)):[]}embeddedAncestors(){const t=[],e=new Set;let r=this.record.parent;for(;r&&"object"==typeof r&&t.length<12;){const n=r,i=String(n.uuid||n.id||"");if(!i||e.has(i))break;e.add(i),t.unshift(new at(n,this.kernel)),r=n.parent}return t}async fetchAncestors(){const t=[],e=new Set;let r=await this.getParent();for(;r&&t.length<12;){const n=r.getUuid()||String(r.raw().id??"");if(!n||e.has(n))break;e.add(n),t.unshift(r),r=await r.getParent()}return t}excludeSelf(t){const e=V(this.record);return t.filter(t=>V(t)!==e).map(t=>new at(t,this.kernel))}async ensure(t){if(!t.some(t=>void 0===this.record[t]))return;const e=this.getUuid()||this.getSlug()||String(this.record.id||"");if(!e)return;const r=F(await this.kernel.request(O().page(this.siteRef(),e)));this.setRecord({...this.record,...r})}}let ct=null;function ut(){if(!ct)throw new Error("Client is not installed.");return ct}function lt(t,e){return null!=e&&""!==String(e)?String(e):t.siteRef()}function pt(t,e){e?.page&&e.page>0&&t.set("page",String(Math.floor(e.page))),e?.perPage&&e.perPage>0&&t.set("per_page",String(Math.floor(e.perPage)))}function ht(t){if(null==t)return!1;if("string"==typeof t){const e=t.trim();return""!==e&&"{}"!==e&&"[]"!==e}return Array.isArray(t)?t.length>0:"object"!=typeof t||Object.keys(t).length>0}function dt(t){if(t&&"object"==typeof t)return t.options}function gt(t){if("string"==typeof t)return t;if(t&&"object"==typeof t)try{return JSON.stringify(t)}catch{return""}return""}async function ft(t,e){const r=ut(),n=lt(r,e),i=F(await r.request(O().page(n,t)));return r.rememberPage(i),new at(i,r)}class mt{constructor(t,e=null){this.record=t,this.kernel=e}record;kernel;getTitle(){return new k(this.record.title)}getUrl(){return new $(this.record.url)}getChildren(){return wt(this.record.children,this.kernel)}isCurrent(t){const e=this.getUrl().path();if(!e)return!1;if(t)return e===t.getUrl().path();const r=this.kernel??St,n=r?.snapshot().page;return!(!r||!n)&&e===new at(n,r).getUrl().path()}getPage(){const t=this.record.page;if(!t||"object"!=typeof t)return null;const e=this.kernel??St;return e?new at(t,e):null}raw(){return{...this.record}}}class yt{constructor(t,e){this.source=t,this.runtime=e}source;runtime;get record(){return"function"==typeof this.source?this.source():this.source}static async find(t,e){const r=function(){if(!St)throw new Error("Client is not installed.");return St}(),n=null!=e&&""!==String(e)?String(e):r.siteRef(),i=r.snapshot().menus,s=i[t]||Object.values(i).find(e=>!!e&&(String(e.uuid)===t||String(e.id)===t||String(e.name)===t||String(e.position)===t));if(s)return new yt(s,r);const o=F(await r.request(O().menu(n,t)));return r.rememberMenu(o),new yt(o,r)}getName(){return new k(this.record.name)}getPosition(){return String(this.record.position||"")}getItems(){return wt(this.record.items,this.runtime)}raw(){return{...this.record}}}function wt(t,e=null){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new mt(t,e)):[]}let St=null;class bt{constructor(t){this.kernel=t}kernel;all(){return function(t,e=function(){return globalThis}()){const r=Array.isArray(t)?t.flatMap(t=>function(t){if(!t||"object"!=typeof t)return[];const e=t,r=$t(String(e.lang??""));return r?[{lang:r,domain:_t(String(e.domain??"")),url:String(e.url??"").trim()}]:[]}(t)):[];return r.length?r.flatMap(t=>{const r=kt(t.url||function(t,e){const r=e[`locale_${t}_baseurl`];return"string"==typeof r?r.trim():""}(t.lang,e)||t.domain);return t.lang&&r?[{lang:t.lang,domain:t.domain||_t(r),url:r}]:[]}):function(t){const e=[];for(const r of Object.keys(t)){const n=/^locale_([a-z]+)_baseurl$/.exec(r);if(!n)continue;const i=kt(String(t[r]??""));i&&e.push({lang:n[1],domain:_t(i),url:i})}return e}(e)}(this.kernel.snapshot().locales)}current(){return $t(String(this.kernel.snapshot().site?.lang||""))}url(t){const e=$t(t),r=this.all().find(t=>t.lang===e);return r?.url??""}}function $t(t){return(t.trim().toLowerCase().replaceAll("_","-").split("-")[0]??"").replace(/[^a-z]/g,"")}function kt(t){const e=t.trim();return e?(/^https?:\/\//i.test(e)?e:`https://${e.replace(/^\/+/,"")}`).replace(/\/+$/,""):""}function _t(t){return t.trim().replace(/^https?:\/\//i,"").replace(/\/.*$/,"")}function xt(t){return`mc_${(String(t??"").trim().split("/").pop()??"").replace(/^@/,"").replace(/[^A-Za-z0-9]+/g,"_").replace(/^_+|_+$/g,"").toUpperCase()}`}function jt(t){if("undefined"==typeof window||""===t)return"";const e=window.__MIRO_WEB_PLUGINS__;if(!Array.isArray(e))return"";for(const r of e){const e=String(r??"").trim().toLowerCase(),n=e.lastIndexOf("/");if(n<=0)continue;const i=e.slice(0,n),s=e.slice(n+1);if(""!==i&&(s===t||At(s)===t))return i}return""}function At(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[^A-Za-z0-9]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()}function vt(t){if("undefined"==typeof window)return{};const e=window[t];return e&&"object"==typeof e?e:{}}function Pt(){const t=Qt(),e=function(){try{const t=globalThis.__INERTIA_PAGE__;if(t?.props)return t.props}catch{}return function(){if("undefined"==typeof document)return null;const t=document.querySelector("[data-page]")?.getAttribute("data-page");if(!t)return null;try{return JSON.parse(t).props??null}catch{return null}}()}();return e&&t.hydrate(e),t}function Ct(){const t=Pt();return Mt(t),new at(()=>t.snapshot().page??{},t)}function Ot(){const t=Pt();return Mt(t),new it(()=>t.snapshot().site??{},t)}function Mt(e){try{const r=function(){try{return Tt??null}catch{return null}}();if(!r)return;const n=r.usePage();e.hydrate(t.unref(n))}catch{}}let Tt=null;function Rt(t){return[...new Set(t)]}function Ut(t,e){const r=new Set(t),n=Rt(e).filter(t=>r.has(t));return Rt(t).forEach((t,e,r)=>{n.includes(t)||n.splice(0===e?0:n.indexOf(r[e-1])+1,0,t)}),n}function It(t,e,r){const n=e.filter(e=>r.includes(e)&&t.includes(e)),i=t.filter(t=>!n.includes(t));return n.forEach(t=>{i.splice(Math.min(e.indexOf(t),i.length),0,t)}),i}function Nt(t,e){const r=t?.options,n=Array.isArray(r)?r.find(t=>t?.key===e)?.value:r?.[e];if("string"!=typeof n)return n;try{return JSON.parse(n)}catch{return}}function Wt(){if("undefined"==typeof window)return null;const t=window;return t.__miroOrder??=new Map,t.__miroOrder}import("@inertiajs/vue3").then(t=>{Tt=t}).catch(()=>{Tt=null});const Et=new Set;function Lt(t){Et.has(t)||Et.add(t)}function Bt(e,r,n){const i=e.filter(e=>e.type!==t.Comment);if(0===i.length)return e;const[s]=i;return i.length>1?(Lt(`Slot „${n}” ma kilka korzeni, więc nie da się go przeciągnąć.`),e):s.type===t.Fragment?Array.isArray(s.children)?e.map(e=>e===s?t.h(t.Fragment,{key:s.key??void 0},Bt(s.children,r,n)):e):e:e.map(e=>e===s?t.cloneVNode(s,r):e)}const qt=t.defineComponent({name:"MiroOrder",inheritAttrs:!1,props:{name:String,source:[String,Array],items:Array,at:Function,scope:{type:String,default:"page"},locked:{type:Array,default:()=>[]}},setup(e,{slots:r}){const n=Ct(),i=Ot(),s=!0===Qt().snapshot().editing,o=()=>"site"===e.scope?i.raw():n.raw(),a=t.shallowRef(null),c=()=>Object.keys(r).filter(t=>"default"!==t&&"$stable"!==t&&!t.startsWith("_")),u=(t,r)=>String(e.at?e.at(t,r):r),l=()=>void 0!==e.items?(()=>{const t=(e.items??[]).map(u);return a.value?Ut(t,a.value):Ut(t,t)})():(()=>{const t=c();return It(Ut(t,a.value??(e.name?function(t,e){const r=Nt(t,"miro_order"),n=r&&"object"==typeof r?r[e]:null;return Array.isArray(n)?n.filter(t=>"string"==typeof t):[]}(o(),e.name):[])),t,e.locked)})(),p=(()=>{const t=o()?.id;if(!s||null==t)return null;const r="site"===e.scope?{site:t}:{page:t};if(void 0===e.items)return e.name?{kind:"site"===e.scope?"site_blocks":"page_blocks",...r,name:e.name}:null;const n=e.source?function(t){const e=Array.isArray(t)?t:t.split(".").map(t=>/^\d+$/.test(t)?Number(t):t),[r,...n]=e;return"string"==typeof r&&""!==r?{key:r,path:n}:null}(e.source):null;if(!n)return null;const i=function(t,e,r){let n=Nt(t,e);for(const i of r){if(!n||"object"!=typeof n)return null;n=n[i]}return Array.isArray(n)?n:null}(o(),n.key,n.path);return!i||!e.at&&i.length!==e.items.length?(Lt(`Lista „${n.key}” różni się od zapisanej. Podaj :at z indeksem w surowej tablicy.`),null):{kind:"site"===e.scope?"site_option":"page_option",...r,key:n.key,path:n.path}})(),h=p?function(t){return"page_blocks"===t.kind||"site_blocks"===t.kind?`${t.kind}:${"page"in t?t.page:t.site}:${t.name}`:`${t.kind}:${"page"in t?t.page:t.site}:${t.key}:${t.path.join(".")}`}(p):"";if(p){const r={id:h,target:p,keys:l,locked:()=>void 0===e.items?e.locked:[],plan:t=>void 0!==e.items?t:It(function(t,e){const r=new Set(e);let n=0;return t.map(t=>r.has(t)?e[n++]:t)}(l(),t),c(),e.locked),apply:t=>{a.value=t}};t.onMounted(()=>Wt()?.set(h,r)),t.onBeforeUnmount(()=>{const t=Wt();t?.get(h)===r&&t.delete(h)})}return()=>{const n=l(),i=void 0!==e.items,s=new Map;i&&e.items.forEach((t,e)=>s.set(u(t,e),t));const o=n.map((o,a)=>{const c={key:o,index:a,first:0===a,last:a===n.length-1},u=i?r.default:r[o],l=u?.(i?{...c,item:s.get(o)}:c)??[],d=p?Bt(l,{"data-miro-order-group":h,"data-miro-order-key":o},i?`${e.source}[${o}]`:o):l;return t.h(t.Fragment,{key:o},d)});return t.h(t.Fragment,null,o)}}}),Gt=/[⁢⁤][​‌‍⁠]+⁣/,zt={b:"strong",i:"em",u:"u",s:"s"};function Ft(e){switch(e.type){case"text":return e.value;case"br":return t.h("br");case"c":return t.h("span",{style:{color:`var(--color-${e.value})`}},Dt(e.children));case"f":return t.h("span",{style:{fontFamily:`var(--font-${e.value})`}},Dt(e.children));default:return t.h(zt[e.type],Dt(e.children))}}function Dt(t){return t.map(Ft)}const Jt=e=>{const r=t.toDisplayString(e.value),n=Gt.test(r);if(!n&&!function(t){return t.includes("[")||t.includes("\n")}(r))return r;const i=Dt(o(r));return n?t.h("span",{"data-miro-rich":"",style:{display:"contents"}},i):1===i.length?i[0]:i};Jt.props=["value"],Jt.displayName="MiroText";class Ht{snap={page:null,site:null,menus:{},locales:[],seo:null,options:{},editing:!1};options;inflight=new Map;cache=new Map;constructor(t={}){this.options=t,t.page&&this.hydrate(t.page),ct=this,st=this,St=this}hydrate(t){return this.snap=D(this.snap,function(t){const e={page:null,site:null,menus:{},locales:[],seo:null,options:{},editing:!1};if(!t||"object"!=typeof t)return e;const r=t,n=J(r.props)?r.props:r;e.page=H(n.page),e.site=H(n.site),e.seo=J(n.seo)?n.seo:null,e.options=J(n.options)?n.options:{},e.locales=Array.isArray(n.locales)?n.locales:[],e.editing=void 0!==n.miroEdit&&null!==n.miroEdit;const i=n.menus;if(J(i))for(const[s,o]of Object.entries(i))e.menus[s]=H(o);return e}(t)),this.snap}snapshot(){return this.snap}apiBase(){return function(t){if(t)return String(t).replace(/\/+$/,"");const e=z();return e.apiBase?String(e.apiBase).replace(/\/+$/,""):function(){if("undefined"==typeof location)return"";const t=String(location.origin||"").replace(/\/+$/,"");if(t&&"null"!==t)return t;const e=location.hostname||"";return e?`${location.protocol}//${e}`:""}()}(this.options.apiBase)}siteBase(){return function(t){if(t)return String(t).replace(/\/+$/,"");const e=z();return e.siteBase?String(e.siteBase).replace(/\/+$/,""):"undefined"!=typeof location?location.origin:""}(this.options.siteBase)}siteRef(){return null!=this.options.site&&""!==String(this.options.site)?String(this.options.site):K(this.snap.site)}async request(t,e={}){const r=String(e.method||"GET").toUpperCase(),n=`${r} ${t}`;if("GET"===r&&this.cache.has(n))return this.cache.get(n);if("GET"===r){const t=this.inflight.get(n);if(t)return t}const i=this.apiBase();if(!i)throw new Error("Remote origin is not configured.");const s=async function(t,e,r={}){const{fetchImpl:n,...i}=r,s=e.startsWith("http")?e:C(t,e),o=n??fetch,a=new Headers(i.headers);a.has("Accept")||a.set("Accept","application/json");const c=await o(s,{...i,headers:a}),u=await c.text();let l=null;if(u)try{l=JSON.parse(u)}catch{l={message:u}}if(!c.ok){const t=new Error(`Request failed (${c.status})`);throw t.status=c.status,t.body=l,t}return l}(i,t,{...e,fetchImpl:this.options.fetch}).then(t=>("GET"===r&&this.cache.set(n,t),t));return"GET"===r&&(this.inflight.set(n,s),s.finally(()=>{this.inflight.delete(n)}).catch(()=>{})),s}rememberPage(t){const e=this.snap.page;e&&String(e.id)===String(t.id)&&(this.snap=D(this.snap,{page:{...e,...t}}))}rememberSite(t){this.snap=D(this.snap,{site:{...this.snap.site??{},...t}})}rememberMenu(t){const e=String(t.position||t.uuid||t.id||t.name||"menu");this.snap=D(this.snap,{menus:{[e]:t}})}}let Vt=null;function Kt(t={}){return Vt=new Ht(t),Vt}function Zt(){return Vt||(Vt=new Ht),Vt}const Yt=Symbol.for("miro.client");function Qt(){return t.inject(Yt,null)??Zt()}function Xt(t={}){return{install(e,r={}){const n=Kt({...t,...r});e.provide(Yt,n),e.component("MiroText",Jt),e.component("MiroOrder",qt),function(t){import("@inertiajs/vue3").then(e=>{const r=e.router;r?.page&&t.hydrate(r.page),r?.on?.("success",e=>{const r=e?.detail?.page;r&&t.hydrate(r)}),r?.on?.("navigate",e=>{const r=e?.detail?.page;r&&t.hydrate(r)})}).catch(()=>{})}(n)}}}const te=Xt(),ee=te;exports.Asset=E,exports.AssetName=_,exports.CollectionCard=Y,exports.Gallery=L,exports.Locales=bt,exports.Menu=yt,exports.MenuItem=mt,exports.MenuTitle=k,exports.Miro=te,exports.MiroOrder=qt,exports.MiroText=Jt,exports.OptionValue=b,exports.Page=at,exports.PageContent=y,exports.PageSmallTitle=f,exports.PageSubtitle=g,exports.PageSummary=m,exports.PageTitle=d,exports.RICH_COLORS=e,exports.RICH_FONTS=r,exports.SDK_KEY=Yt,exports.SeoDescription=j,exports.SeoTitle=x,exports.Site=it,exports.SiteName=S,exports.SiteTitle=w,exports.TextValue=h,exports.UrlValue=$,exports.createMiro=Xt,exports.createRuntime=Kt,exports.default=ee,exports.getRuntime=Zt,exports.parseRichText=o,exports.plainText=c,exports.pluginWindowKey=xt,exports.useKernel=Qt,exports.useMiroAssets=function(){return Ct().getAssets()},exports.useMiroConfig=function(){const e=Qt();return{apiBase:t.computed(()=>e.apiBase()),siteBase:t.computed(()=>e.siteBase()),siteRef:t.computed(()=>e.siteRef())}},exports.useMiroLocales=function(){const t=Pt();return Mt(t),new bt(t)},exports.useMiroMenu=function(t="topbar"){const e=Pt();return Mt(e),new yt(()=>e.snapshot().menus[t]??{position:t,items:[]},e)},exports.useMiroPage=Ct,exports.useMiroSite=Ot,exports.usePlugin=function(t){return function(t,e){const r=xt(t),n=function(t){const e=String(t??"").trim();if(e.includes("/")){const[t,...r]=e.split("/");return{vendor:t||"miroart",slug:At(r.join("/")||e)}}const r=At(e);return{vendor:jt(r)||"miroart",slug:r}}(t);return new Proxy({name:t,key:r,ready:async()=>async function(t){const e=Date.now();for(;Date.now()-e<4e3;){const e=vt(t);if(Object.keys(e).length)return e;await new Promise(t=>setTimeout(t,50))}return vt(t)}(r),api:()=>vt(r),call:(t,...e)=>{const n=vt(r),i=n[t];if("function"!=typeof i)throw new Error(`Missing plugin method: ${t}`);return i.apply(n,e)},request:async(t="/",r={})=>{const i=O().plugins(n.vendor,n.slug,t||"/"),s=new Headers(r.headers);let o=r.body;return void 0!==r.json&&(o=JSON.stringify(r.json)),F(await e.request(i,{...r,headers:s,body:o}))}},{get(t,e,n){if(e in t)return Reflect.get(t,e,n);if("then"===e||e===Symbol.toStringTag)return;const i=vt(r),s=i[String(e)];return"function"==typeof s?s.bind(i):s},has:(t,e)=>e in t||e in vt(r)})}(t,Qt())};
package/dist/index.d.ts CHANGED
@@ -11,10 +11,11 @@ import { createRuntime, getRuntime } from "./runtime";
11
11
  import { useMiroAssets, useMiroConfig, useMiroLocales, useMiroMenu, useMiroPage, useMiroSite, usePlugin } from "./composables";
12
12
  import { AssetName, MenuTitle, OptionValue, PageContent, PageSmallTitle, PageSubtitle, PageSummary, PageTitle, SeoDescription, SeoTitle, SiteName, SiteTitle, TextValue, UrlValue } from "./values";
13
13
  import { pluginWindowKey } from "./plugin";
14
+ import { MiroOrder } from "./MiroOrder";
14
15
  import { MiroText } from "./MiroText";
15
16
  import { parseRichText, plainText, RICH_COLORS, RICH_FONTS, type RichColor, type RichFont, type RichNode } from "./richText";
16
17
  import type { ActionCall, ClientOptions } from "./types";
17
- export { Asset, AssetName, MiroText, parseRichText, plainText, RICH_COLORS, RICH_FONTS, CollectionCard, createMiro, createRuntime, Gallery, getRuntime, Locales, Menu, MenuItem, MenuTitle, Miro, OptionValue, Page, PageContent, PageSmallTitle, PageSubtitle, PageSummary, PageTitle, pluginWindowKey, SDK_KEY, SeoDescription, SeoTitle, Site, SiteName, SiteTitle, TextValue, UrlValue, useKernel, useMiroAssets, useMiroConfig, useMiroLocales, useMiroMenu, useMiroPage, useMiroSite, usePlugin, };
18
+ export { Asset, AssetName, MiroOrder, MiroText, parseRichText, plainText, RICH_COLORS, RICH_FONTS, CollectionCard, createMiro, createRuntime, Gallery, getRuntime, Locales, Menu, MenuItem, MenuTitle, Miro, OptionValue, Page, PageContent, PageSmallTitle, PageSubtitle, PageSummary, PageTitle, pluginWindowKey, SDK_KEY, SeoDescription, SeoTitle, Site, SiteName, SiteTitle, TextValue, UrlValue, useKernel, useMiroAssets, useMiroConfig, useMiroLocales, useMiroMenu, useMiroPage, useMiroSite, usePlugin, };
18
19
  export type { ActionCall, ClientOptions, GalleryMembership, LocaleLink, PageGallery, PageListMeta, PageListQuery, PagedPages, RichColor, RichFont, RichNode, SeoView, };
19
20
  declare const plugin: Plugin;
20
21
  export default plugin;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{toDisplayString as t,h as e,inject as r,computed as n,unref as i}from"vue";const s=["primary","secondary","accent","neutral","base-100","base-content","info","success","warning","error"],o=["sans","serif"],c=/\\(\[\/?(?:b|i|u|s|c|f)(?:=[a-z0-9-]+)?\])|\[(\/?)(b|i|u|s|c|f)(?:=([a-z0-9-]+))?\]/g;function a(t,e){return"c"===t?s.includes(e??""):"f"===t?o.includes(e??""):void 0===e}function u(t,e){""!==e&&e.split(/\r?\n/).forEach((e,r)=>{if(r>0&&t.push({type:"br"}),""===e)return;const n=t[t.length-1];"text"===n?.type?n.value+=e:t.push({type:"text",value:e})})}function l(t){const e=String(t??""),r=[],n=[],i=()=>n[n.length-1]?.children??r,s=()=>{var t,e;t=n.pop(),e=i(),0!==t.children.length&&("c"===t.tag?e.push({type:"c",value:t.value,children:t.children}):"f"===t.tag?e.push({type:"f",value:t.value,children:t.children}):e.push({type:t.tag,children:t.children}))};let o,l=0;for(c.lastIndex=0;null!==(o=c.exec(e));){u(i(),e.slice(l,o.index)),l=c.lastIndex;const[t,r,h,p,d]=o;if(void 0===r){if("/"===h){const e=void 0===d?n.map(t=>t.tag).lastIndexOf(p):-1;if(-1===e){u(i(),t);continue}for(;n.length>e;)s();continue}!a(p,d)||n.length>=8?u(i(),t):n.push({tag:p,value:d??null,children:[]})}else u(i(),r)}for(u(i(),e.slice(l));n.length>0;)s();return r}function h(t,e){for(const r of t)"text"===r.type?e.push(r.value):"br"===r.type?e.push("\n"):h(r.children,e)}function p(t){const e=String(t??"");if(!e.includes("["))return e;const r=[];return h(l(e),r),r.join("")}const d=/[⁢⁤][​‌‍⁠]+⁣/,g={b:"strong",i:"em",u:"u",s:"s"};function f(t){switch(t.type){case"text":return t.value;case"br":return e("br");case"c":return e("span",{style:{color:`var(--color-${t.value})`}},m(t.children));case"f":return e("span",{style:{fontFamily:`var(--font-${t.value})`}},m(t.children));default:return e(g[t.type],m(t.children))}}function m(t){return t.map(f)}const y=r=>{const n=t(r.value),i=d.test(n);if(!i&&!function(t){return t.includes("[")||t.includes("\n")}(n))return n;const s=m(l(n));return i?e("span",{"data-miro-rich":"",style:{display:"contents"}},s):1===s.length?s[0]:s};function w(t,e){return{page:void 0!==e.page?e.page:t.page,site:void 0!==e.site?e.site:t.site,menus:e.menus?{...t.menus,...e.menus}:{...t.menus},locales:e.locales??t.locales,seo:void 0!==e.seo?e.seo:t.seo,options:e.options?{...t.options,...e.options}:{...t.options}}}function S(t){return Boolean(t)&&"object"==typeof t&&!Array.isArray(t)}function b(t){return S(t)?t:null}function $(t){return t?String(t.uuid||t.ulid||t.id||t.slug||t.full_url||""):""}function _(t){return t?String(t.uuid||t.domain||t.id||""):""}function k(t){return String.fromCharCode(...t.map(t=>23^t))}function j(t,e){const r=String(t||"").replace(/\/+$/,""),n=e.startsWith("/")?e:`/${e}`;return r?`${r}${n}`:n}function A(){const t=k([56,118,103,126]),e=k([97,38]),r=k([100,126,99,114,100]),n=k([103,118,112,114,100]),i=k([100,114,118,101,116,127]),s=k([122,114,121,98,100]),o=k([122,114,115,126,118]),c=k([103,123,98,112,126,121,100]),a=k([118,116,99,126,120,121,100]);return{sites:()=>j("",`${t}/${e}/${r}`),site:n=>j("",`${t}/${e}/${r}/${encodeURIComponent(n)}`),pages:i=>j("",`${t}/${e}/${r}/${encodeURIComponent(i)}/${n}`),page:(i,s)=>j("",`${t}/${e}/${r}/${encodeURIComponent(i)}/${n}/${s.split("/").map(t=>encodeURIComponent(t)).join("/")}`),search:s=>j("",`${t}/${e}/${r}/${encodeURIComponent(s)}/${n}/${i}`),menus:n=>j("",`${t}/${e}/${r}/${encodeURIComponent(n)}/${s}`),menu:(n,i)=>j("",`${t}/${e}/${r}/${encodeURIComponent(n)}/${s}/${encodeURIComponent(i)}`),media:e=>j("",`${t}/${o}/${encodeURIComponent(e)}`),action:e=>j("",`${t}/${a}/${encodeURIComponent(e)}`),plugins:(e,r,n="")=>{const i=`${t}/${c}/${encodeURIComponent(e)}/${encodeURIComponent(r)}`;return n&&"/"!==n?`${i}${n.startsWith("/")?n:`/${n}`}`:i}}}function v(){if("undefined"==typeof globalThis)return{};const t=globalThis.MiroConfig;return t&&"object"==typeof t?t:{}}function x(t){return t&&"object"==typeof t&&"data"in t?t.data:t}function P(t){return null==t?"":"string"==typeof t?t:"number"==typeof t||"boolean"==typeof t?String(t):""}function C(t){const e=P(t);if(!e)return"";if("undefined"!=typeof document){const t=document.createElement("textarea");return t.innerHTML=e,t.value}return e.replace(/&#(\d+);/g,(t,e)=>String.fromCharCode(Number(e))).replace(/&#x([0-9a-f]+);/gi,(t,e)=>String.fromCharCode(parseInt(e,16))).replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">")}function R(t){return p(C(t)).replace(/<script[\s\S]*?>[\s\S]*?<\/script>/gi," ").replace(/<style[\s\S]*?>[\s\S]*?<\/style>/gi," ").replace(/<[^>]+>/g," ").replace(/\s+/g," ").trim()}y.props=["value"],y.displayName="MiroText";class U extends String{kind;extra;constructor(t,e,r={}){super(C(e)),this.kind=t,this.extra=r,Object.setPrototypeOf(this,new.target.prototype)}toString(){return String.prototype.toString.call(this)}valueOf(){return String.prototype.valueOf.call(this)}raw(){return this.toString()}decode(){return C(this.toString())}cleanContent(){return R(this.toString())}stripHtml(){return this.cleanContent()}plain(){return p(this.toString())}excerpt(t=160){const e=this.cleanContent();return e.length<=t?e:`${e.slice(0,Math.max(0,t-1)).trimEnd()}…`}firstParagraph(){return function(t){const e=C(t),r=e.match(/<p\b[^>]*>([\s\S]*?)<\/p>/i);return R(r?r[1]:e)}(this.toString())}isEmpty(){return""===this.cleanContent()}json(){const t=this.toString().trim();if(!t)return null;try{return JSON.parse(t)}catch{return null}}bool(){const t=this.toString().trim().toLowerCase();return"1"===t||"true"===t||"yes"===t||"on"===t}number(){const t=Number(this.toString().trim());return Number.isFinite(t)?t:null}}class I extends U{constructor(t){super("PageTitle",t)}}class T extends U{constructor(t){super("PageSubtitle",t)}}class M extends U{constructor(t){super("PageSmallTitle",t)}}class N extends U{constructor(t){super("PageSummary",t)}}class O extends U{constructor(t){super("PageContent",t)}html(){return this.toString()}}class W extends U{constructor(t){super("SiteTitle",t)}}class B extends U{constructor(t){super("SiteName",t)}}class L extends U{key;structured;constructor(t,e){const r=D(e);super("OptionValue",r.text,{key:t}),this.key=t,this.structured=r.structured}json(){return void 0!==this.structured?this.structured:super.json()}present(){return!this.isEmpty()}}class q extends U{constructor(t){super("UrlValue",t)}path(){const t=this.toString().trim();if(!t)return"/";try{if(/^https?:\/\//i.test(t))return new URL(t).pathname.replace(/\/+$/,"")||"/"}catch{}return(t.startsWith("/")?t:`/${t}`).replace(/\/+$/,"")||"/"}href(t=""){const e=this.path();return!t||/^https?:\/\//i.test(e)?e:`${String(t).replace(/\/+$/,"")}${e}`}}class E extends U{constructor(t){super("MenuTitle",t)}}class G extends U{constructor(t){super("AssetName",t)}}class z extends U{constructor(t){super("SeoTitle",t)}}class J extends U{constructor(t){super("SeoDescription",t)}}function D(t){if(null==t)return{text:""};if("boolean"==typeof t||"number"==typeof t)return{text:String(t)};if("string"==typeof t){const e=t.trim();if(""===e||"[]"===e||"{}"===e)return{text:""};if(e.startsWith("{")&&e.endsWith("}")||e.startsWith("[")&&e.endsWith("]")||e.startsWith('"')&&e.endsWith('"'))try{return D(JSON.parse(e))}catch{return{text:C(t)}}return{text:C(t)}}return Array.isArray(t)?{text:JSON.stringify(t),structured:t}:"object"==typeof t?function(t){return"value"in t&&Object.keys(t).every(t=>"value"===t||"key"===t||"id"===t||"active"===t)}(t)?D(t.value):{text:JSON.stringify(t),structured:t}:{text:P(t)}}function F(t,e){if(!t)return"";if(Array.isArray(t)){const r=t.find(t=>t&&"object"==typeof t&&t.key===e);return r&&"object"==typeof r?r.value:""}return"object"==typeof t?t[e]:""}function H(t){if("string"==typeof t){const e=t.trim();return e?X(e)?{uuid:e}:{url:e,path:e}:null}if(!t||"object"!=typeof t||Array.isArray(t))return null;const e=t,r=K(e.source),n=Z(e.url,e.preview_url,e.path,e.src,r?.url,r?.preview_url,r?.path),i=Z(e.uuid,r?.uuid);if(n||i&&X(i))return e;const s=Z(e.value);return s?H(s):null}function Z(...t){for(const e of t)if("string"==typeof e&&""!==e.trim())return e.trim();return""}function V(t){return"string"==typeof t?t.trim():""}function K(t){return!t||"object"!=typeof t||Array.isArray(t)?null:t}function Q(t){return t.startsWith("/media/")||t.startsWith("/_images/")||t.startsWith("/api/media/")||t.startsWith("/branding-assets/")||t.startsWith("/storage/")}function X(t){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t)}const Y=[{mark:"1_8",width:256},{mark:"1_4",width:512},{mark:"1_2",width:1024},{mark:"2_3",width:1400}];class tt{constructor(t,e){this.record=t,this.runtime=e}record;runtime;getUuid(){return String(this.record.uuid||this.record.id||"")}getName(){return new G(this.record.name)}getAlt(){return V(this.record.alt)}getCaption(){return V(this.record.caption)}getGallery(){return this.memberships()[0]??null}galleryUuid(){return this.memberships()[0]?.uuid??""}galleryName(){return this.memberships()[0]?.name??""}memberships(){const t=this.record.galleries;if(Array.isArray(t)&&t.length>0)return t.map(t=>rt(t)).filter(t=>null!==t);const e=String(this.record.gallery_uuid??"").trim(),r=String(this.record.gallery_name??"").trim();if(!e&&!r)return[];const n=this.record.gallery_id;return[{id:"number"==typeof n||"string"==typeof n?n:null,uuid:e,name:r,sort_order:nt(this.record.gallery_sort_order)}]}getMime(){const t=K(this.record.source);return String(this.record.mime_type||t?.mime_type||"")}getSize(){const t=K(this.record.source),e=Number(this.record.size??t?.size??0);return Number.isFinite(e)?e:0}getType(){const t=V(this.record.type);if(t)return t;const e=this.getMime();return e.startsWith("image/")?"image":e.startsWith("video/")?"video":"application/pdf"===e?"pdf":""}getSortOrder(){const t=Number(this.record.sort_order??0);return Number.isFinite(t)?t:0}isImage(){return!!this.getMime().startsWith("image/")||/\.(jpe?g|png|gif|webp|svg)(\?|$)/i.test(this.urlString())}url(){return new q(this.urlString())}srcset(){const t=this.urlString();if(!t||/\.svg([?#]|$)/i.test(t)||/^https?:\/\//i.test(t)||t.startsWith("//"))return"";if(!/\.webp([?#]|$)/i.test(t)||/\.(?:1_16|1_8|1_4|1_2|2_3)\.webp([?#]|$)/i.test(t))return"";const e=Y.map(({mark:e,width:r})=>`${t.replace(/\.webp([?#].*)?$/i,`.${e}.webp$1`)} ${r}w`);return e.push(`${t} 2048w`),e.join(", ")}raw(){return{...this.record}}urlString(){const t=K(this.record.source),e=Z(this.record.uuid,t?.uuid),r=Z(this.record.disk,t?.disk);let n=Z(this.record.url,this.record.preview_url,this.record.path,this.record.src,t?.url,t?.preview_url,t?.path);if(e&&X(e)&&n&&function(t,e){return!!(/\/project-storage\//i.test(r=t)||/\/editor\/project-file/i.test(r)||/cms\.miroart\.pl/i.test(r)&&/\/(?:project-storage|storage)\//i.test(r))||"project_public"===e&&!Q(t)&&!/^https?:\/\//i.test(t)&&!t.startsWith("//");var r}(n,r))return this.mediaUrl(e);if(!n)return e&&X(e)?this.mediaUrl(e):"";if(!0===globalThis.isSsg){if(n.startsWith("/_images/")||n.startsWith("_images/"))return n.startsWith("/")?n:`/${n}`;const e=function(t){const e=t.match(/[?&]path=([^&]+)/i);if(e)try{const t=decodeURIComponent(e[1].replace(/\+/g," ")).split(/[/\\]/).pop()||"";if(t&&"project-file"!==t.toLowerCase())return t.trim()}catch{}return(t.split("#")[0].split("?")[0].split(/[/\\]/).pop()||"").trim()}(Z(t?.path,this.record.path,n)),r=/\.(jpe?g|png|gif|webp|svg)$/i.test(i=e)?/\.svg$/i.test(i)?`/_images/${i}`:`/_images/${i.replace(/\.(jpe?g|png|gif|webp)$/i,".webp")}`:null;if(r)return r}var i;if(/^https?:\/\//i.test(n)||n.startsWith("//"))return n;if(n.startsWith("_images/"))return`/${n}`;if(Q(n))return n;n.includes("/")||n.includes("\\")||X(n)||(n=`images/${n}`);const s=n.startsWith("/")?n:`/${n}`;return Q(s)||s.startsWith("/project-storage/")?s:`/storage${s}`}mediaUrl(t){const e=A().media(t),r=this.runtime.apiBase();return r?j(r,e):e}}class et{constructor(t){this.items=t}items;all(){return this.items.slice()}first(){return this.items[0]??null}extra(){return this.items.slice(1)}hero(){return this.first()}urls(){return this.items.map(t=>t.url())}isEmpty(){return 0===this.items.length}count(){return this.items.length}[Symbol.iterator](){return this.items[Symbol.iterator]()}}function rt(t){if(!t||"object"!=typeof t)return null;const e=t,r=String(e.uuid??"").trim(),n=String(e.name??"").trim();if(!r&&!n)return null;const i=e.id;return{id:"number"==typeof i||"string"==typeof i?i:null,uuid:r,name:n,sort_order:nt(e.sort_order)}}function nt(t){const e=Number(t??0);return Number.isFinite(e)?e:0}function it(t,e){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new tt(t,e)):[]}const st=/* @__PURE__ */new Set(["id","uuid","created_at","updated_at"]);class ot{constructor(t,e){this.row=t,this.kernel=e}row;kernel;getHref(){return new q(this.row.href)}getTitle(){return String(this.row.title??"")}item(){const t=this.row.item;return t&&"object"==typeof t?t:{}}image(){return ct(this.item(),this.kernel)}}function ct(t,e){if(!t||"object"!=typeof t)return null;for(const[r,n]of Object.entries(t)){if(st.has(r)||"string"!=typeof n||!at(n))continue;const t=H(n);if(t)return new tt(t,e)}return null}function at(t){const e=t.trim();return!!e&&(!!(e.startsWith("/media/")||e.startsWith("/_images/")||e.startsWith("_images/")||e.startsWith("/api/media/")||e.startsWith("/branding-assets/"))||/\.(jpe?g|png|gif|webp|svg)(\?|#|$)/i.test(e))}function ut(t,e){const r=t&&"object"==typeof t?t.meta:null,n=r&&"object"==typeof r?r:{};return{currentPage:ht(n.current_page,1),lastPage:ht(n.last_page,1),perPage:ht(n.per_page,Math.max(e,1)),total:pt(n.total,e)}}function lt(t,e){return Object.assign(t,{meta:e})}function ht(t,e){const r=Number(t);return!Number.isFinite(r)||r<1?e:Math.floor(r)}function pt(t,e){if(null==t||""===t)return e;const r=Number(t);return!Number.isFinite(r)||r<0?e:Math.floor(r)}class dt{constructor(t,e){this.source=t,this.kernel=e}source;kernel;get record(){return"function"==typeof this.source?this.source():this.source}static async all(){const t=ft(),e=await t.request(A().sites());return(Array.isArray(e?.data)?e.data:[]).filter(t=>Boolean(t)&&"object"==typeof t).map(e=>new dt(e,t))}static async find(t){const e=ft(),r=null!=t&&""!==String(t)?String(t):e.siteRef(),n=e.snapshot().site;if(n&&(!t||String(n.uuid)===String(t)||String(n.id)===String(t)||String(n.domain)===String(t)||_(n)===String(t)))return new dt(n,e);const i=x(await e.request(A().site(r)));return e.rememberSite(i),new dt(i,e)}static async findPage(t,e){return mt.find(t,e)}static async findMenu(t,e){return vt.find(t,e)}getName(){return new B(this.record.name)}getTitle(){const t=F(this.record.options,"seo_title")||F(this.record.options,"title");return new W(t||this.record.name)}getDomain(){return String(this.record.domain||"")}getLang(){return String(this.record.lang||"")}getUuid(){return String(this.record.uuid||"")}getOption(t){return new L(t,F(this.record.options,t))}getImage(t){const e=this.getOption(t),r=e.json(),n=null==r?e.toString().trim():r;if(null==n||""===n)return null;const i=H(n);return i?new tt(i,this.kernel):null}async findPage(t){return mt.find(t,this.ref())}async findMenu(t){return vt.find(t,this.ref())}async menus(){const t=this.kernel.snapshot().menus,e=Object.values(t).filter(Boolean);return e.length?e.map(t=>new vt(t,this.kernel)):((await this.kernel.request(A().menus(this.ref()))).data??[]).map(t=>(this.kernel.rememberMenu(t),new vt(t,this.kernel)))}async pages(t={}){const e=new URLSearchParams,r={...t};null!=r.perPage&&null==r.per_page&&(r.per_page=r.perPage,delete r.perPage);for(const[o,c]of Object.entries(r))e.set(o,String(c));const n=e.toString()?`?${e.toString()}`:"",i=await this.kernel.request(`${A().pages(this.ref())}${n}`),s=(i.data??[]).map(t=>(this.kernel.rememberPage(t),new mt(t,this.kernel)));return lt(s,ut(i,s.length))}async runAction(t){const e=String(t.uuid||"").trim();if(!e)throw new Error("Action uuid is required.");const r=String(this.record.domain||this.ref());return this.kernel.request(A().action(r),{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({uuid:e,method:t.method||"GET",path:t.path||"",query:t.query||{},body:t.body||"",headers:t.headers||{},params:t.params||{},post:t.post||{}})})}raw(){return{...this.record}}ref(){return String(this.record.uuid||this.record.domain||this.record.id||this.kernel.siteRef())}}let gt=null;function ft(){if(!gt)throw new Error("Client is not installed.");return gt}class mt{constructor(t,e){this.source=t,this.kernel=e}source;kernel;get record(){return"function"==typeof this.source?this.source():this.source}setRecord(t){"function"!=typeof this.source?this.source=t:this.kernel.rememberPage(t)}static async findByUlid(t,e){return jt(t,e)}static async find(t,e){return jt(t,e)}static async search(t,e,r){const n=wt(),i=St(n,e),s=new URLSearchParams;s.set("q",t),bt(s,r);const o=await n.request(`${A().search(i)}?${s.toString()}`),c=(Array.isArray(o?.data)?o.data:Array.isArray(o)?o:[]).map(t=>(n.rememberPage(t),new mt(t,n)));return lt(c,ut(o,c.length))}getTitle(){return new I(this.record.title)}getSubtitle(){return new T(this.record.subtitle)}getSmallTitle(){return new M(this.record.smalltitle)}getSummary(){return new N(this.record.summary)}getContent(){return new O(this.record.content)}getSlug(){return String(this.record.slug||"")}getUrl(){return new q(this.record.full_url||(this.record.slug?`/${this.record.slug}`:"/"))}getUuid(){return String(this.record.uuid||this.record.ulid||"")}getId(){return String(this.record.id||this.getUuid())}getLayout(){return String(this.record.layout||"")}getDisplay(){return String(this.record.display||"")}getDisplayInMenu(){const t=this.record.display_in_menu;return null==t||""===t||!1!==t&&0!==t&&"0"!==t}getSortOrder(){const t=Number(this.record.sort_order??0);return Number.isFinite(t)?t:0}getLang(){const t=String(this.record.lang||"").trim();if(t)return t;const e=this.kernel.snapshot().site;return String(e?.lang||function(t){return t&&"object"==typeof t?String(t.lang||""):""}(this.record.site)||"")}getOption(t){const e=[F(this.record.options,t),this.kernel.snapshot().options[t],F(this.kernel.snapshot().site?.options,t),F(_t(this.record.site),t)];for(const r of e)if($t(r))return new L(t,r);return new L(t,"")}getSeo(){const t=this.seoBag(),e=t=>null==t?"":String(t),r=t=>{const e=H(t);return e?new tt(e,this.kernel):null};return{title:new z(t.title??this.record.title),description:new J(t.description??this.record.summary),keywords:e(t.keywords),robots:e(t.robots),canonical:new q(t.canonical),ogTitle:e(t.og_title??t.title??this.record.title),ogDescription:e(t.og_description??t.description??this.record.summary),ogImage:r(t.og_image),ogType:e(t.og_type),ogUrl:new q(t.og_url||t.canonical),twitterCard:e(t.twitter_card),twitterTitle:e(t.twitter_title??t.og_title??t.title),twitterDescription:e(t.twitter_description??t.og_description??t.description),twitterImage:r(t.twitter_image||t.og_image),ldJson:kt(t.ld_json),raw:{...t}}}get collectionItem(){const t=this.record.collectionItem;return t&&"object"==typeof t?t:{}}get collectionItems(){const t=this.record.collectionItems;return t&&"object"==typeof t?t:{}}get collectionGallery(){return t=this.record.collectionGallery,e=this.kernel,Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new ot(t,e)):[];var t,e}collectionImage(){return ct(this.collectionItem,this.kernel)}getAssets(){return new et(it(this.record.assets,this.kernel))}getGallery(t){const e=t.trim();if(!e)return new et([]);const r=[];return it(this.record.assets,this.kernel).forEach((t,n)=>{const i=t.memberships().find(t=>function(t,e){const r=e.trim().toLocaleLowerCase();return!!r&&(t.uuid.toLocaleLowerCase()===r||t.name.toLocaleLowerCase()===r)}(t,e));i&&r.push({asset:t,sort:i.sort_order,index:n})}),r.sort((t,e)=>t.sort-e.sort||t.index-e.index),new et(r.map(t=>t.asset))}getGalleries(){const t=it(this.record.assets,this.kernel);return this.galleryList(t).map(t=>({id:t.id,uuid:t.uuid,name:t.name,description:t.description,sort_order:t.sort_order,assets:this.getGallery(t.uuid||t.name)}))}async getChildren(t){const e=function(t){if(!Array.isArray(t))return[];const e=/* @__PURE__ */new Set(["options","assets"]),r=[];for(const n of t){const t=String(n).trim().toLowerCase();e.has(t)&&!r.includes(t)&&r.push(t)}return r}(t?.with),r=Array.isArray(this.record.children)?this.record.children:null;if(r&&function(t,e){return!e.length||t.every(t=>{if(!t||"object"!=typeof t)return!1;const r=t;if(e.includes("options")){const t=r.options;if(null==t||"object"!=typeof t)return!1}return!(e.includes("assets")&&!Array.isArray(r.assets))})}(r,e)){const e=function(t,e,r){const n=t.length;if(!e&&!r)return{items:t,meta:{currentPage:1,lastPage:1,perPage:Math.max(n,1),total:n}};const i=r&&r>0?Math.floor(r):Math.max(n,1),s=e&&e>0?Math.floor(e):1,o=Math.max(1,Math.ceil(n/i)),c=(s-1)*i;return{items:t.slice(c,c+i),meta:{currentPage:s,lastPage:o,perPage:i,total:n}}}(this.rowsToPages(r),t?.page,t?.perPage);return lt(e.items,e.meta)}const n=this.getUuid()||String(this.record.id??"");if(!n){const t=r?this.rowsToPages(r):[];return lt(t,ut(null,t.length))}const i=new URLSearchParams;i.set("parent",n),e.length&&i.set("with",e.join(",")),bt(i,t);const s=await this.kernel.request(`${A().pages(this.siteRef())}?${i.toString()}`);return lt(this.rowsToPages(s.data??[]),ut(s,(s.data??[]).length))}async getSiblings(){if(Array.isArray(this.record.siblings))return this.record.siblings.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new mt(t,this.kernel));const t=this.record.parent_id,e=this.siteRef();if(null==t||""===t){const t=await this.kernel.request(`${A().pages(e)}?parent=root`);return this.excludeSelf(t.data??[])}const r=await this.kernel.request(`${A().pages(e)}?parent=${encodeURIComponent(String(t))}`);return this.excludeSelf(r.data??[])}async getParent(){if(this.record.parent&&"object"==typeof this.record.parent)return new mt(this.record.parent,this.kernel);const t=this.record.parent_id;return null==t||""===t?null:jt(String(t),this.siteRef())}async getAncestors(){if(Array.isArray(this.record.ancestors))return this.rowsToPages(this.record.ancestors);const t=this.embeddedAncestors();if(t.length){const e=t[0],r=e.raw().parent_id;return null==r||""===r||0===r?t:[...await e.fetchAncestors(),...t]}return this.fetchAncestors()}async getSite(){if(this.record.site&&"object"==typeof this.record.site)return new dt(this.record.site,this.kernel);const t=this.kernel.snapshot().site;if(t&&(String(t.id)===String(this.record.site_id)||!this.record.site_id))return new dt(t,this.kernel);const e=this.record.site_id?String(this.record.site_id):this.kernel.siteRef(),r=x(await this.kernel.request(A().site(e)));return this.kernel.rememberSite(r),new dt(r,this.kernel)}async load(){return await this.ensure(["content","options","assets","children"]),this}raw(){return{...this.record}}seoBag(){const t=this.record.seo&&"object"==typeof this.record.seo?this.record.seo:this.kernel.snapshot().seo;return t&&"object"==typeof t?{...t}:{}}galleryList(t){if(Array.isArray(this.record.galleries))return this.record.galleries.flatMap(t=>{const e=rt(t);if(!e)return[];const r=t&&"object"==typeof t?String(t.description??""):"";return[{...e,description:r}]});const e=/* @__PURE__ */new Map;for(const r of t)for(const t of r.memberships()){const r=(t.uuid||t.name).toLocaleLowerCase();r&&!e.has(r)&&e.set(r,{...t,description:""})}return[...e.values()]}siteRef(){return this.record.site&&"object"==typeof this.record.site?_(this.record.site)||this.kernel.siteRef():this.record.site_id?String(this.record.site_id):this.kernel.siteRef()}rowsToPages(t){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new mt(t,this.kernel)):[]}embeddedAncestors(){const t=[],e=/* @__PURE__ */new Set;let r=this.record.parent;for(;r&&"object"==typeof r&&t.length<12;){const n=r,i=String(n.uuid||n.id||"");if(!i||e.has(i))break;e.add(i),t.unshift(new mt(n,this.kernel)),r=n.parent}return t}async fetchAncestors(){const t=[],e=/* @__PURE__ */new Set;let r=await this.getParent();for(;r&&t.length<12;){const n=r.getUuid()||String(r.raw().id??"");if(!n||e.has(n))break;e.add(n),t.unshift(r),r=await r.getParent()}return t}excludeSelf(t){const e=$(this.record);return t.filter(t=>$(t)!==e).map(t=>new mt(t,this.kernel))}async ensure(t){if(!t.some(t=>void 0===this.record[t]))return;const e=this.getUuid()||this.getSlug()||String(this.record.id||"");if(!e)return;const r=x(await this.kernel.request(A().page(this.siteRef(),e)));this.setRecord({...this.record,...r})}}let yt=null;function wt(){if(!yt)throw new Error("Client is not installed.");return yt}function St(t,e){return null!=e&&""!==String(e)?String(e):t.siteRef()}function bt(t,e){e?.page&&e.page>0&&t.set("page",String(Math.floor(e.page))),e?.perPage&&e.perPage>0&&t.set("per_page",String(Math.floor(e.perPage)))}function $t(t){if(null==t)return!1;if("string"==typeof t){const e=t.trim();return""!==e&&"{}"!==e&&"[]"!==e}return Array.isArray(t)?t.length>0:"object"!=typeof t||Object.keys(t).length>0}function _t(t){if(t&&"object"==typeof t)return t.options}function kt(t){if("string"==typeof t)return t;if(t&&"object"==typeof t)try{return JSON.stringify(t)}catch{return""}return""}async function jt(t,e){const r=wt(),n=St(r,e),i=x(await r.request(A().page(n,t)));return r.rememberPage(i),new mt(i,r)}class At{constructor(t,e=null){this.record=t,this.kernel=e}record;kernel;getTitle(){return new E(this.record.title)}getUrl(){return new q(this.record.url)}getChildren(){return xt(this.record.children,this.kernel)}isCurrent(t){const e=this.getUrl().path();if(!e)return!1;if(t)return e===t.getUrl().path();const r=this.kernel??Pt,n=r?.snapshot().page;return!(!r||!n)&&e===new mt(n,r).getUrl().path()}getPage(){const t=this.record.page;if(!t||"object"!=typeof t)return null;const e=this.kernel??Pt;return e?new mt(t,e):null}raw(){return{...this.record}}}class vt{constructor(t,e){this.source=t,this.runtime=e}source;runtime;get record(){return"function"==typeof this.source?this.source():this.source}static async find(t,e){const r=function(){if(!Pt)throw new Error("Client is not installed.");return Pt}(),n=null!=e&&""!==String(e)?String(e):r.siteRef(),i=r.snapshot().menus,s=i[t]||Object.values(i).find(e=>!!e&&(String(e.uuid)===t||String(e.id)===t||String(e.name)===t||String(e.position)===t));if(s)return new vt(s,r);const o=x(await r.request(A().menu(n,t)));return r.rememberMenu(o),new vt(o,r)}getName(){return new E(this.record.name)}getPosition(){return String(this.record.position||"")}getItems(){return xt(this.record.items,this.runtime)}raw(){return{...this.record}}}function xt(t,e=null){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new At(t,e)):[]}let Pt=null;class Ct{snap={page:null,site:null,menus:{},locales:[],seo:null,options:{}};options;inflight=/* @__PURE__ */new Map;cache=/* @__PURE__ */new Map;constructor(t={}){this.options=t,t.page&&this.hydrate(t.page),yt=this,gt=this,Pt=this}hydrate(t){return this.snap=w(this.snap,function(t){const e={page:null,site:null,menus:{},locales:[],seo:null,options:{}};if(!t||"object"!=typeof t)return e;const r=t,n=S(r.props)?r.props:r;e.page=b(n.page),e.site=b(n.site),e.seo=S(n.seo)?n.seo:null,e.options=S(n.options)?n.options:{},e.locales=Array.isArray(n.locales)?n.locales:[];const i=n.menus;if(S(i))for(const[s,o]of Object.entries(i))e.menus[s]=b(o);return e}(t)),this.snap}snapshot(){return this.snap}apiBase(){return function(t){if(t)return String(t).replace(/\/+$/,"");const e=v();return e.apiBase?String(e.apiBase).replace(/\/+$/,""):function(){if("undefined"==typeof location)return"";const t=String(location.origin||"").replace(/\/+$/,"");if(t&&"null"!==t)return t;const e=location.hostname||"";return e?`${location.protocol}//${e}`:""}()}(this.options.apiBase)}siteBase(){return function(t){if(t)return String(t).replace(/\/+$/,"");const e=v();return e.siteBase?String(e.siteBase).replace(/\/+$/,""):"undefined"!=typeof location?location.origin:""}(this.options.siteBase)}siteRef(){return null!=this.options.site&&""!==String(this.options.site)?String(this.options.site):_(this.snap.site)}async request(t,e={}){const r=String(e.method||"GET").toUpperCase(),n=`${r} ${t}`;if("GET"===r&&this.cache.has(n))return this.cache.get(n);if("GET"===r){const t=this.inflight.get(n);if(t)return t}const i=this.apiBase();if(!i)throw new Error("Remote origin is not configured.");const s=async function(t,e,r={}){const{fetchImpl:n,...i}=r,s=e.startsWith("http")?e:j(t,e),o=n??fetch,c=new Headers(i.headers);c.has("Accept")||c.set("Accept","application/json");const a=await o(s,{...i,headers:c}),u=await a.text();let l=null;if(u)try{l=JSON.parse(u)}catch{l={message:u}}if(!a.ok){const t=new Error(`Request failed (${a.status})`);throw t.status=a.status,t.body=l,t}return l}(i,t,{...e,fetchImpl:this.options.fetch}).then(t=>("GET"===r&&this.cache.set(n,t),t));return"GET"===r&&(this.inflight.set(n,s),s.finally(()=>{this.inflight.delete(n)}).catch(()=>{})),s}rememberPage(t){const e=this.snap.page;e&&String(e.id)===String(t.id)&&(this.snap=w(this.snap,{page:{...e,...t}}))}rememberSite(t){this.snap=w(this.snap,{site:{...this.snap.site??{},...t}})}rememberMenu(t){const e=String(t.position||t.uuid||t.id||t.name||"menu");this.snap=w(this.snap,{menus:{[e]:t}})}}let Rt=null;function Ut(t={}){return Rt=new Ct(t),Rt}function It(){return Rt||(Rt=new Ct),Rt}const Tt=/* @__PURE__ */Symbol.for("miro.client");function Mt(){return r(Tt,null)??It()}function Nt(t={}){return{install(e,r={}){const n=Ut({...t,...r});e.provide(Tt,n),e.component("MiroText",y),function(t){import("@inertiajs/vue3").then(e=>{const r=e.router;r?.page&&t.hydrate(r.page),r?.on?.("success",e=>{const r=e?.detail?.page;r&&t.hydrate(r)}),r?.on?.("navigate",e=>{const r=e?.detail?.page;r&&t.hydrate(r)})}).catch(()=>{})}(n)}}}const Ot=Nt();class Wt{constructor(t){this.kernel=t}kernel;all(){return function(t,e=function(){return globalThis}()){const r=Array.isArray(t)?t.flatMap(t=>function(t){if(!t||"object"!=typeof t)return[];const e=t,r=Bt(String(e.lang??""));return r?[{lang:r,domain:qt(String(e.domain??"")),url:String(e.url??"").trim()}]:[]}(t)):[];return r.length?r.flatMap(t=>{const r=Lt(t.url||function(t,e){const r=e[`locale_${t}_baseurl`];return"string"==typeof r?r.trim():""}(t.lang,e)||t.domain);return t.lang&&r?[{lang:t.lang,domain:t.domain||qt(r),url:r}]:[]}):function(t){const e=[];for(const r of Object.keys(t)){const n=/^locale_([a-z]+)_baseurl$/.exec(r);if(!n)continue;const i=Lt(String(t[r]??""));i&&e.push({lang:n[1],domain:qt(i),url:i})}return e}(e)}(this.kernel.snapshot().locales)}current(){return Bt(String(this.kernel.snapshot().site?.lang||""))}url(t){const e=Bt(t),r=this.all().find(t=>t.lang===e);return r?.url??""}}function Bt(t){return(t.trim().toLowerCase().replaceAll("_","-").split("-")[0]??"").replace(/[^a-z]/g,"")}function Lt(t){const e=t.trim();return e?(/^https?:\/\//i.test(e)?e:`https://${e.replace(/^\/+/,"")}`).replace(/\/+$/,""):""}function qt(t){return t.trim().replace(/^https?:\/\//i,"").replace(/\/.*$/,"")}function Et(t){return`mc_${(String(t??"").trim().split("/").pop()??"").replace(/^@/,"").replace(/[^A-Za-z0-9]+/g,"_").replace(/^_+|_+$/g,"").toUpperCase()}`}function Gt(t){if("undefined"==typeof window||""===t)return"";const e=window.__MIRO_WEB_PLUGINS__;if(!Array.isArray(e))return"";for(const r of e){const e=String(r??"").trim().toLowerCase(),n=e.lastIndexOf("/");if(n<=0)continue;const i=e.slice(0,n),s=e.slice(n+1);if(""!==i&&(s===t||zt(s)===t))return i}return""}function zt(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[^A-Za-z0-9]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()}function Jt(t){if("undefined"==typeof window)return{};const e=window[t];return e&&"object"==typeof e?e:{}}function Dt(){const t=Mt(),e=function(){try{const t=globalThis.__INERTIA_PAGE__;if(t?.props)return t.props}catch{}return function(){if("undefined"==typeof document)return null;const t=document.querySelector("[data-page]")?.getAttribute("data-page");if(!t)return null;try{return JSON.parse(t).props??null}catch{return null}}()}();return e&&t.hydrate(e),t}function Ft(){const t=Dt();return Yt(t),new mt(()=>t.snapshot().page??{},t)}function Ht(){const t=Dt();return Yt(t),new dt(()=>t.snapshot().site??{},t)}function Zt(t="topbar"){const e=Dt();return Yt(e),new vt(()=>e.snapshot().menus[t]??{position:t,items:[]},e)}function Vt(){const t=Dt();return Yt(t),new Wt(t)}function Kt(){return Ft().getAssets()}function Qt(t){return function(t,e){const r=Et(t),n=function(t){const e=String(t??"").trim();if(e.includes("/")){const[t,...r]=e.split("/");return{vendor:t||"miroart",slug:zt(r.join("/")||e)}}const r=zt(e);return{vendor:Gt(r)||"miroart",slug:r}}(t);return new Proxy({name:t,key:r,ready:async()=>async function(t){const e=Date.now();for(;Date.now()-e<4e3;){const e=Jt(t);if(Object.keys(e).length)return e;await new Promise(t=>setTimeout(t,50))}return Jt(t)}(r),api:()=>Jt(r),call:(t,...e)=>{const n=Jt(r),i=n[t];if("function"!=typeof i)throw new Error(`Missing plugin method: ${t}`);return i.apply(n,e)},request:async(t="/",r={})=>{const i=A().plugins(n.vendor,n.slug,t||"/"),s=new Headers(r.headers);let o=r.body;return void 0!==r.json&&(o=JSON.stringify(r.json)),x(await e.request(i,{...r,headers:s,body:o}))}},{get(t,e,n){if(e in t)return Reflect.get(t,e,n);if("then"===e||e===Symbol.toStringTag)return;const i=Jt(r),s=i[String(e)];return"function"==typeof s?s.bind(i):s},has:(t,e)=>e in t||e in Jt(r)})}(t,Mt())}function Xt(){const t=Mt();return{apiBase:n(()=>t.apiBase()),siteBase:n(()=>t.siteBase()),siteRef:n(()=>t.siteRef())}}function Yt(t){try{const e=function(){try{return te??null}catch{return null}}();if(!e)return;const r=e.usePage();t.hydrate(i(r))}catch{}}let te=null;import("@inertiajs/vue3").then(t=>{te=t}).catch(()=>{te=null});const ee=Ot;export{tt as Asset,G as AssetName,ot as CollectionCard,et as Gallery,Wt as Locales,vt as Menu,At as MenuItem,E as MenuTitle,Ot as Miro,y as MiroText,L as OptionValue,mt as Page,O as PageContent,M as PageSmallTitle,T as PageSubtitle,N as PageSummary,I as PageTitle,s as RICH_COLORS,o as RICH_FONTS,Tt as SDK_KEY,J as SeoDescription,z as SeoTitle,dt as Site,B as SiteName,W as SiteTitle,U as TextValue,q as UrlValue,Nt as createMiro,Ut as createRuntime,ee as default,It as getRuntime,l as parseRichText,p as plainText,Et as pluginWindowKey,Mt as useKernel,Kt as useMiroAssets,Xt as useMiroConfig,Vt as useMiroLocales,Zt as useMiroMenu,Ft as useMiroPage,Ht as useMiroSite,Qt as usePlugin};
1
+ import{computed as t,unref as e,defineComponent as r,shallowRef as n,onMounted as i,onBeforeUnmount as s,h as o,Fragment as a,Comment as c,cloneVNode as u,toDisplayString as l,inject as h}from"vue";const p=["primary","secondary","accent","neutral","base-100","base-content","info","success","warning","error"],d=["sans","serif"],g=/\\(\[\/?(?:b|i|u|s|c|f)(?:=[a-z0-9-]+)?\])|\[(\/?)(b|i|u|s|c|f)(?:=([a-z0-9-]+))?\]/g;function f(t,e){return"c"===t?p.includes(e??""):"f"===t?d.includes(e??""):void 0===e}function m(t,e){""!==e&&e.split(/\r?\n/).forEach((e,r)=>{if(r>0&&t.push({type:"br"}),""===e)return;const n=t[t.length-1];"text"===n?.type?n.value+=e:t.push({type:"text",value:e})})}function y(t){const e=String(t??""),r=[],n=[],i=()=>n[n.length-1]?.children??r,s=()=>{var t,e;t=n.pop(),e=i(),0!==t.children.length&&("c"===t.tag?e.push({type:"c",value:t.value,children:t.children}):"f"===t.tag?e.push({type:"f",value:t.value,children:t.children}):e.push({type:t.tag,children:t.children}))};let o,a=0;for(g.lastIndex=0;null!==(o=g.exec(e));){m(i(),e.slice(a,o.index)),a=g.lastIndex;const[t,r,c,u,l]=o;if(void 0===r){if("/"===c){const e=void 0===l?n.map(t=>t.tag).lastIndexOf(u):-1;if(-1===e){m(i(),t);continue}for(;n.length>e;)s();continue}!f(u,l)||n.length>=8?m(i(),t):n.push({tag:u,value:l??null,children:[]})}else m(i(),r)}for(m(i(),e.slice(a));n.length>0;)s();return r}function w(t,e){for(const r of t)"text"===r.type?e.push(r.value):"br"===r.type?e.push("\n"):w(r.children,e)}function S(t){const e=String(t??"");if(!e.includes("["))return e;const r=[];return w(y(e),r),r.join("")}function b(t){return null==t?"":"string"==typeof t?t:"number"==typeof t||"boolean"==typeof t?String(t):""}function $(t){const e=b(t);if(!e)return"";if("undefined"!=typeof document){const t=document.createElement("textarea");return t.innerHTML=e,t.value}return e.replace(/&#(\d+);/g,(t,e)=>String.fromCharCode(Number(e))).replace(/&#x([0-9a-f]+);/gi,(t,e)=>String.fromCharCode(parseInt(e,16))).replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">")}function k(t){return S($(t)).replace(/<script[\s\S]*?>[\s\S]*?<\/script>/gi," ").replace(/<style[\s\S]*?>[\s\S]*?<\/style>/gi," ").replace(/<[^>]+>/g," ").replace(/\s+/g," ").trim()}class _ extends String{kind;extra;constructor(t,e,r={}){super($(e)),this.kind=t,this.extra=r,Object.setPrototypeOf(this,new.target.prototype)}toString(){return String.prototype.toString.call(this)}valueOf(){return String.prototype.valueOf.call(this)}raw(){return this.toString()}decode(){return $(this.toString())}cleanContent(){return k(this.toString())}stripHtml(){return this.cleanContent()}plain(){return S(this.toString())}excerpt(t=160){const e=this.cleanContent();return e.length<=t?e:`${e.slice(0,Math.max(0,t-1)).trimEnd()}…`}firstParagraph(){return function(t){const e=$(t),r=e.match(/<p\b[^>]*>([\s\S]*?)<\/p>/i);return k(r?r[1]:e)}(this.toString())}isEmpty(){return""===this.cleanContent()}json(){const t=this.toString().trim();if(!t)return null;try{return JSON.parse(t)}catch{return null}}bool(){const t=this.toString().trim().toLowerCase();return"1"===t||"true"===t||"yes"===t||"on"===t}number(){const t=Number(this.toString().trim());return Number.isFinite(t)?t:null}}class j extends _{constructor(t){super("PageTitle",t)}}class A extends _{constructor(t){super("PageSubtitle",t)}}class v extends _{constructor(t){super("PageSmallTitle",t)}}class x extends _{constructor(t){super("PageSummary",t)}}class P extends _{constructor(t){super("PageContent",t)}html(){return this.toString()}}class C extends _{constructor(t){super("SiteTitle",t)}}class O extends _{constructor(t){super("SiteName",t)}}class R extends _{key;structured;constructor(t,e){const r=W(e);super("OptionValue",r.text,{key:t}),this.key=t,this.structured=r.structured}json(){return void 0!==this.structured?this.structured:super.json()}present(){return!this.isEmpty()}}class U extends _{constructor(t){super("UrlValue",t)}path(){const t=this.toString().trim();if(!t)return"/";try{if(/^https?:\/\//i.test(t))return new URL(t).pathname.replace(/\/+$/,"")||"/"}catch{}return(t.startsWith("/")?t:`/${t}`).replace(/\/+$/,"")||"/"}href(t=""){const e=this.path();return!t||/^https?:\/\//i.test(e)?e:`${String(t).replace(/\/+$/,"")}${e}`}}class M extends _{constructor(t){super("MenuTitle",t)}}class I extends _{constructor(t){super("AssetName",t)}}class T extends _{constructor(t){super("SeoTitle",t)}}class N extends _{constructor(t){super("SeoDescription",t)}}function W(t){if(null==t)return{text:""};if("boolean"==typeof t||"number"==typeof t)return{text:String(t)};if("string"==typeof t){const e=t.trim();if(""===e||"[]"===e||"{}"===e)return{text:""};if(e.startsWith("{")&&e.endsWith("}")||e.startsWith("[")&&e.endsWith("]")||e.startsWith('"')&&e.endsWith('"'))try{return W(JSON.parse(e))}catch{return{text:$(t)}}return{text:$(t)}}return Array.isArray(t)?{text:JSON.stringify(t),structured:t}:"object"==typeof t?function(t){return"value"in t&&Object.keys(t).every(t=>"value"===t||"key"===t||"id"===t||"active"===t)}(t)?W(t.value):{text:JSON.stringify(t),structured:t}:{text:b(t)}}function E(t,e){if(!t)return"";if(Array.isArray(t)){const r=t.find(t=>t&&"object"==typeof t&&t.key===e);return r&&"object"==typeof r?r.value:""}return"object"==typeof t?t[e]:""}function B(t){return String.fromCharCode(...t.map(t=>23^t))}function L(t,e){const r=String(t||"").replace(/\/+$/,""),n=e.startsWith("/")?e:`/${e}`;return r?`${r}${n}`:n}function q(){const t=B([56,118,103,126]),e=B([97,38]),r=B([100,126,99,114,100]),n=B([103,118,112,114,100]),i=B([100,114,118,101,116,127]),s=B([122,114,121,98,100]),o=B([122,114,115,126,118]),a=B([103,123,98,112,126,121,100]),c=B([118,116,99,126,120,121,100]);return{sites:()=>L("",`${t}/${e}/${r}`),site:n=>L("",`${t}/${e}/${r}/${encodeURIComponent(n)}`),pages:i=>L("",`${t}/${e}/${r}/${encodeURIComponent(i)}/${n}`),page:(i,s)=>L("",`${t}/${e}/${r}/${encodeURIComponent(i)}/${n}/${s.split("/").map(t=>encodeURIComponent(t)).join("/")}`),search:s=>L("",`${t}/${e}/${r}/${encodeURIComponent(s)}/${n}/${i}`),menus:n=>L("",`${t}/${e}/${r}/${encodeURIComponent(n)}/${s}`),menu:(n,i)=>L("",`${t}/${e}/${r}/${encodeURIComponent(n)}/${s}/${encodeURIComponent(i)}`),media:e=>L("",`${t}/${o}/${encodeURIComponent(e)}`),action:e=>L("",`${t}/${c}/${encodeURIComponent(e)}`),plugins:(e,r,n="")=>{const i=`${t}/${a}/${encodeURIComponent(e)}/${encodeURIComponent(r)}`;return n&&"/"!==n?`${i}${n.startsWith("/")?n:`/${n}`}`:i}}}function z(t){if("string"==typeof t){const e=t.trim();return e?H(e)?{uuid:e}:{url:e,path:e}:null}if(!t||"object"!=typeof t||Array.isArray(t))return null;const e=t,r=F(e.source),n=G(e.url,e.preview_url,e.path,e.src,r?.url,r?.preview_url,r?.path),i=G(e.uuid,r?.uuid);if(n||i&&H(i))return e;const s=G(e.value);return s?z(s):null}function G(...t){for(const e of t)if("string"==typeof e&&""!==e.trim())return e.trim();return""}function J(t){return"string"==typeof t?t.trim():""}function F(t){return!t||"object"!=typeof t||Array.isArray(t)?null:t}function D(t){return t.startsWith("/media/")||t.startsWith("/_images/")||t.startsWith("/api/media/")||t.startsWith("/branding-assets/")||t.startsWith("/storage/")}function H(t){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t)}const Z=[{mark:"1_8",width:256},{mark:"1_4",width:512},{mark:"1_2",width:1024},{mark:"2_3",width:1400}];class V{constructor(t,e){this.record=t,this.runtime=e}record;runtime;getUuid(){return String(this.record.uuid||this.record.id||"")}getName(){return new I(this.record.name)}getAlt(){return J(this.record.alt)}getCaption(){return J(this.record.caption)}getGallery(){return this.memberships()[0]??null}galleryUuid(){return this.memberships()[0]?.uuid??""}galleryName(){return this.memberships()[0]?.name??""}memberships(){const t=this.record.galleries;if(Array.isArray(t)&&t.length>0)return t.map(t=>Q(t)).filter(t=>null!==t);const e=String(this.record.gallery_uuid??"").trim(),r=String(this.record.gallery_name??"").trim();if(!e&&!r)return[];const n=this.record.gallery_id;return[{id:"number"==typeof n||"string"==typeof n?n:null,uuid:e,name:r,sort_order:X(this.record.gallery_sort_order)}]}getMime(){const t=F(this.record.source);return String(this.record.mime_type||t?.mime_type||"")}getSize(){const t=F(this.record.source),e=Number(this.record.size??t?.size??0);return Number.isFinite(e)?e:0}getType(){const t=J(this.record.type);if(t)return t;const e=this.getMime();return e.startsWith("image/")?"image":e.startsWith("video/")?"video":"application/pdf"===e?"pdf":""}getSortOrder(){const t=Number(this.record.sort_order??0);return Number.isFinite(t)?t:0}isImage(){return!!this.getMime().startsWith("image/")||/\.(jpe?g|png|gif|webp|svg)(\?|$)/i.test(this.urlString())}url(){return new U(this.urlString())}srcset(){const t=this.urlString();if(!t||/\.svg([?#]|$)/i.test(t)||/^https?:\/\//i.test(t)||t.startsWith("//"))return"";if(!/\.webp([?#]|$)/i.test(t)||/\.(?:1_16|1_8|1_4|1_2|2_3)\.webp([?#]|$)/i.test(t))return"";const e=Z.map(({mark:e,width:r})=>`${t.replace(/\.webp([?#].*)?$/i,`.${e}.webp$1`)} ${r}w`);return e.push(`${t} 2048w`),e.join(", ")}raw(){return{...this.record}}urlString(){const t=F(this.record.source),e=G(this.record.uuid,t?.uuid),r=G(this.record.disk,t?.disk);let n=G(this.record.url,this.record.preview_url,this.record.path,this.record.src,t?.url,t?.preview_url,t?.path);if(e&&H(e)&&n&&function(t,e){return!!(/\/project-storage\//i.test(r=t)||/\/editor\/project-file/i.test(r)||/cms\.miroart\.pl/i.test(r)&&/\/(?:project-storage|storage)\//i.test(r))||"project_public"===e&&!D(t)&&!/^https?:\/\//i.test(t)&&!t.startsWith("//");var r}(n,r))return this.mediaUrl(e);if(!n)return e&&H(e)?this.mediaUrl(e):"";if(!0===globalThis.isSsg){if(n.startsWith("/_images/")||n.startsWith("_images/"))return n.startsWith("/")?n:`/${n}`;const e=function(t){const e=t.match(/[?&]path=([^&]+)/i);if(e)try{const t=decodeURIComponent(e[1].replace(/\+/g," ")).split(/[/\\]/).pop()||"";if(t&&"project-file"!==t.toLowerCase())return t.trim()}catch{}return(t.split("#")[0].split("?")[0].split(/[/\\]/).pop()||"").trim()}(G(t?.path,this.record.path,n)),r=/\.(jpe?g|png|gif|webp|svg)$/i.test(i=e)?/\.svg$/i.test(i)?`/_images/${i}`:`/_images/${i.replace(/\.(jpe?g|png|gif|webp)$/i,".webp")}`:null;if(r)return r}var i;if(/^https?:\/\//i.test(n)||n.startsWith("//"))return n;if(n.startsWith("_images/"))return`/${n}`;if(D(n))return n;n.includes("/")||n.includes("\\")||H(n)||(n=`images/${n}`);const s=n.startsWith("/")?n:`/${n}`;return D(s)||s.startsWith("/project-storage/")?s:`/storage${s}`}mediaUrl(t){const e=q().media(t),r=this.runtime.apiBase();return r?L(r,e):e}}class K{constructor(t){this.items=t}items;all(){return this.items.slice()}first(){return this.items[0]??null}extra(){return this.items.slice(1)}hero(){return this.first()}urls(){return this.items.map(t=>t.url())}isEmpty(){return 0===this.items.length}count(){return this.items.length}[Symbol.iterator](){return this.items[Symbol.iterator]()}}function Q(t){if(!t||"object"!=typeof t)return null;const e=t,r=String(e.uuid??"").trim(),n=String(e.name??"").trim();if(!r&&!n)return null;const i=e.id;return{id:"number"==typeof i||"string"==typeof i?i:null,uuid:r,name:n,sort_order:X(e.sort_order)}}function X(t){const e=Number(t??0);return Number.isFinite(e)?e:0}function Y(t,e){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new V(t,e)):[]}function tt(){if("undefined"==typeof globalThis)return{};const t=globalThis.MiroConfig;return t&&"object"==typeof t?t:{}}function et(t){return t&&"object"==typeof t&&"data"in t?t.data:t}function rt(t,e){return{page:void 0!==e.page?e.page:t.page,site:void 0!==e.site?e.site:t.site,menus:e.menus?{...t.menus,...e.menus}:{...t.menus},locales:e.locales??t.locales,seo:void 0!==e.seo?e.seo:t.seo,options:e.options?{...t.options,...e.options}:{...t.options},editing:e.editing??t.editing}}function nt(t){return Boolean(t)&&"object"==typeof t&&!Array.isArray(t)}function it(t){return nt(t)?t:null}function st(t){return t?String(t.uuid||t.ulid||t.id||t.slug||t.full_url||""):""}function ot(t){return t?String(t.uuid||t.domain||t.id||""):""}const at=/* @__PURE__ */new Set(["id","uuid","created_at","updated_at"]);class ct{constructor(t,e){this.row=t,this.kernel=e}row;kernel;getHref(){return new U(this.row.href)}getTitle(){return String(this.row.title??"")}item(){const t=this.row.item;return t&&"object"==typeof t?t:{}}image(){return ut(this.item(),this.kernel)}}function ut(t,e){if(!t||"object"!=typeof t)return null;for(const[r,n]of Object.entries(t)){if(at.has(r)||"string"!=typeof n||!lt(n))continue;const t=z(n);if(t)return new V(t,e)}return null}function lt(t){const e=t.trim();return!!e&&(!!(e.startsWith("/media/")||e.startsWith("/_images/")||e.startsWith("_images/")||e.startsWith("/api/media/")||e.startsWith("/branding-assets/"))||/\.(jpe?g|png|gif|webp|svg)(\?|#|$)/i.test(e))}function ht(t,e){const r=t&&"object"==typeof t?t.meta:null,n=r&&"object"==typeof r?r:{};return{currentPage:dt(n.current_page,1),lastPage:dt(n.last_page,1),perPage:dt(n.per_page,Math.max(e,1)),total:gt(n.total,e)}}function pt(t,e){return Object.assign(t,{meta:e})}function dt(t,e){const r=Number(t);return!Number.isFinite(r)||r<1?e:Math.floor(r)}function gt(t,e){if(null==t||""===t)return e;const r=Number(t);return!Number.isFinite(r)||r<0?e:Math.floor(r)}class ft{constructor(t,e){this.source=t,this.kernel=e}source;kernel;get record(){return"function"==typeof this.source?this.source():this.source}static async all(){const t=yt(),e=await t.request(q().sites());return(Array.isArray(e?.data)?e.data:[]).filter(t=>Boolean(t)&&"object"==typeof t).map(e=>new ft(e,t))}static async find(t){const e=yt(),r=null!=t&&""!==String(t)?String(t):e.siteRef(),n=e.snapshot().site;if(n&&(!t||String(n.uuid)===String(t)||String(n.id)===String(t)||String(n.domain)===String(t)||ot(n)===String(t)))return new ft(n,e);const i=et(await e.request(q().site(r)));return e.rememberSite(i),new ft(i,e)}static async findPage(t,e){return wt.find(t,e)}static async findMenu(t,e){return Pt.find(t,e)}getName(){return new O(this.record.name)}getTitle(){const t=E(this.record.options,"seo_title")||E(this.record.options,"title");return new C(t||this.record.name)}getDomain(){return String(this.record.domain||"")}getLang(){return String(this.record.lang||"")}getUuid(){return String(this.record.uuid||"")}getOption(t){return new R(t,E(this.record.options,t))}getImage(t){const e=this.getOption(t),r=e.json(),n=null==r?e.toString().trim():r;if(null==n||""===n)return null;const i=z(n);return i?new V(i,this.kernel):null}async findPage(t){return wt.find(t,this.ref())}async findMenu(t){return Pt.find(t,this.ref())}async menus(){const t=this.kernel.snapshot().menus,e=Object.values(t).filter(Boolean);return e.length?e.map(t=>new Pt(t,this.kernel)):((await this.kernel.request(q().menus(this.ref()))).data??[]).map(t=>(this.kernel.rememberMenu(t),new Pt(t,this.kernel)))}async pages(t={}){const e=new URLSearchParams,r={...t};null!=r.perPage&&null==r.per_page&&(r.per_page=r.perPage,delete r.perPage);for(const[o,a]of Object.entries(r))e.set(o,String(a));const n=e.toString()?`?${e.toString()}`:"",i=await this.kernel.request(`${q().pages(this.ref())}${n}`),s=(i.data??[]).map(t=>(this.kernel.rememberPage(t),new wt(t,this.kernel)));return pt(s,ht(i,s.length))}async runAction(t){const e=String(t.uuid||"").trim();if(!e)throw new Error("Action uuid is required.");const r=String(this.record.domain||this.ref());return this.kernel.request(q().action(r),{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({uuid:e,method:t.method||"GET",path:t.path||"",query:t.query||{},body:t.body||"",headers:t.headers||{},params:t.params||{},post:t.post||{}})})}raw(){return{...this.record}}ref(){return String(this.record.uuid||this.record.domain||this.record.id||this.kernel.siteRef())}}let mt=null;function yt(){if(!mt)throw new Error("Client is not installed.");return mt}class wt{constructor(t,e){this.source=t,this.kernel=e}source;kernel;get record(){return"function"==typeof this.source?this.source():this.source}setRecord(t){"function"!=typeof this.source?this.source=t:this.kernel.rememberPage(t)}static async findByUlid(t,e){return vt(t,e)}static async find(t,e){return vt(t,e)}static async search(t,e,r){const n=bt(),i=$t(n,e),s=new URLSearchParams;s.set("q",t),kt(s,r);const o=await n.request(`${q().search(i)}?${s.toString()}`),a=(Array.isArray(o?.data)?o.data:Array.isArray(o)?o:[]).map(t=>(n.rememberPage(t),new wt(t,n)));return pt(a,ht(o,a.length))}getTitle(){return new j(this.record.title)}getSubtitle(){return new A(this.record.subtitle)}getSmallTitle(){return new v(this.record.smalltitle)}getSummary(){return new x(this.record.summary)}getContent(){return new P(this.record.content)}getSlug(){return String(this.record.slug||"")}getUrl(){return new U(this.record.full_url||(this.record.slug?`/${this.record.slug}`:"/"))}getUuid(){return String(this.record.uuid||this.record.ulid||"")}getId(){return String(this.record.id||this.getUuid())}getLayout(){return String(this.record.layout||"")}getDisplay(){return String(this.record.display||"")}getDisplayInMenu(){const t=this.record.display_in_menu;return null==t||""===t||!1!==t&&0!==t&&"0"!==t}getSortOrder(){const t=Number(this.record.sort_order??0);return Number.isFinite(t)?t:0}getLang(){const t=String(this.record.lang||"").trim();if(t)return t;const e=this.kernel.snapshot().site;return String(e?.lang||function(t){return t&&"object"==typeof t?String(t.lang||""):""}(this.record.site)||"")}getOption(t){const e=[E(this.record.options,t),this.kernel.snapshot().options[t],E(this.kernel.snapshot().site?.options,t),E(jt(this.record.site),t)];for(const r of e)if(_t(r))return new R(t,r);return new R(t,"")}getSeo(){const t=this.seoBag(),e=t=>null==t?"":String(t),r=t=>{const e=z(t);return e?new V(e,this.kernel):null};return{title:new T(t.title??this.record.title),description:new N(t.description??this.record.summary),keywords:e(t.keywords),robots:e(t.robots),canonical:new U(t.canonical),ogTitle:e(t.og_title??t.title??this.record.title),ogDescription:e(t.og_description??t.description??this.record.summary),ogImage:r(t.og_image),ogType:e(t.og_type),ogUrl:new U(t.og_url||t.canonical),twitterCard:e(t.twitter_card),twitterTitle:e(t.twitter_title??t.og_title??t.title),twitterDescription:e(t.twitter_description??t.og_description??t.description),twitterImage:r(t.twitter_image||t.og_image),ldJson:At(t.ld_json),raw:{...t}}}get collectionItem(){const t=this.record.collectionItem;return t&&"object"==typeof t?t:{}}get collectionItems(){const t=this.record.collectionItems;return t&&"object"==typeof t?t:{}}get collectionGallery(){return t=this.record.collectionGallery,e=this.kernel,Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new ct(t,e)):[];var t,e}collectionImage(){return ut(this.collectionItem,this.kernel)}getAssets(){return new K(Y(this.record.assets,this.kernel))}getGallery(t){const e=t.trim();if(!e)return new K([]);const r=[];return Y(this.record.assets,this.kernel).forEach((t,n)=>{const i=t.memberships().find(t=>function(t,e){const r=e.trim().toLocaleLowerCase();return!!r&&(t.uuid.toLocaleLowerCase()===r||t.name.toLocaleLowerCase()===r)}(t,e));i&&r.push({asset:t,sort:i.sort_order,index:n})}),r.sort((t,e)=>t.sort-e.sort||t.index-e.index),new K(r.map(t=>t.asset))}getGalleries(){const t=Y(this.record.assets,this.kernel);return this.galleryList(t).map(t=>({id:t.id,uuid:t.uuid,name:t.name,description:t.description,sort_order:t.sort_order,assets:this.getGallery(t.uuid||t.name)}))}async getChildren(t){const e=function(t){if(!Array.isArray(t))return[];const e=/* @__PURE__ */new Set(["options","assets"]),r=[];for(const n of t){const t=String(n).trim().toLowerCase();e.has(t)&&!r.includes(t)&&r.push(t)}return r}(t?.with),r=Array.isArray(this.record.children)?this.record.children:null;if(r&&function(t,e){return!e.length||t.every(t=>{if(!t||"object"!=typeof t)return!1;const r=t;if(e.includes("options")){const t=r.options;if(null==t||"object"!=typeof t)return!1}return!(e.includes("assets")&&!Array.isArray(r.assets))})}(r,e)){const e=function(t,e,r){const n=t.length;if(!e&&!r)return{items:t,meta:{currentPage:1,lastPage:1,perPage:Math.max(n,1),total:n}};const i=r&&r>0?Math.floor(r):Math.max(n,1),s=e&&e>0?Math.floor(e):1,o=Math.max(1,Math.ceil(n/i)),a=(s-1)*i;return{items:t.slice(a,a+i),meta:{currentPage:s,lastPage:o,perPage:i,total:n}}}(this.rowsToPages(r),t?.page,t?.perPage);return pt(e.items,e.meta)}const n=this.getUuid()||String(this.record.id??"");if(!n){const t=r?this.rowsToPages(r):[];return pt(t,ht(null,t.length))}const i=new URLSearchParams;i.set("parent",n),e.length&&i.set("with",e.join(",")),kt(i,t);const s=await this.kernel.request(`${q().pages(this.siteRef())}?${i.toString()}`);return pt(this.rowsToPages(s.data??[]),ht(s,(s.data??[]).length))}async getSiblings(){if(Array.isArray(this.record.siblings))return this.record.siblings.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new wt(t,this.kernel));const t=this.record.parent_id,e=this.siteRef();if(null==t||""===t){const t=await this.kernel.request(`${q().pages(e)}?parent=root`);return this.excludeSelf(t.data??[])}const r=await this.kernel.request(`${q().pages(e)}?parent=${encodeURIComponent(String(t))}`);return this.excludeSelf(r.data??[])}async getParent(){if(this.record.parent&&"object"==typeof this.record.parent)return new wt(this.record.parent,this.kernel);const t=this.record.parent_id;return null==t||""===t?null:vt(String(t),this.siteRef())}async getAncestors(){if(Array.isArray(this.record.ancestors))return this.rowsToPages(this.record.ancestors);const t=this.embeddedAncestors();if(t.length){const e=t[0],r=e.raw().parent_id;return null==r||""===r||0===r?t:[...await e.fetchAncestors(),...t]}return this.fetchAncestors()}async getSite(){if(this.record.site&&"object"==typeof this.record.site)return new ft(this.record.site,this.kernel);const t=this.kernel.snapshot().site;if(t&&(String(t.id)===String(this.record.site_id)||!this.record.site_id))return new ft(t,this.kernel);const e=this.record.site_id?String(this.record.site_id):this.kernel.siteRef(),r=et(await this.kernel.request(q().site(e)));return this.kernel.rememberSite(r),new ft(r,this.kernel)}async load(){return await this.ensure(["content","options","assets","children"]),this}raw(){return{...this.record}}seoBag(){const t=this.record.seo&&"object"==typeof this.record.seo?this.record.seo:this.kernel.snapshot().seo;return t&&"object"==typeof t?{...t}:{}}galleryList(t){if(Array.isArray(this.record.galleries))return this.record.galleries.flatMap(t=>{const e=Q(t);if(!e)return[];const r=t&&"object"==typeof t?String(t.description??""):"";return[{...e,description:r}]});const e=/* @__PURE__ */new Map;for(const r of t)for(const t of r.memberships()){const r=(t.uuid||t.name).toLocaleLowerCase();r&&!e.has(r)&&e.set(r,{...t,description:""})}return[...e.values()]}siteRef(){return this.record.site&&"object"==typeof this.record.site?ot(this.record.site)||this.kernel.siteRef():this.record.site_id?String(this.record.site_id):this.kernel.siteRef()}rowsToPages(t){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new wt(t,this.kernel)):[]}embeddedAncestors(){const t=[],e=/* @__PURE__ */new Set;let r=this.record.parent;for(;r&&"object"==typeof r&&t.length<12;){const n=r,i=String(n.uuid||n.id||"");if(!i||e.has(i))break;e.add(i),t.unshift(new wt(n,this.kernel)),r=n.parent}return t}async fetchAncestors(){const t=[],e=/* @__PURE__ */new Set;let r=await this.getParent();for(;r&&t.length<12;){const n=r.getUuid()||String(r.raw().id??"");if(!n||e.has(n))break;e.add(n),t.unshift(r),r=await r.getParent()}return t}excludeSelf(t){const e=st(this.record);return t.filter(t=>st(t)!==e).map(t=>new wt(t,this.kernel))}async ensure(t){if(!t.some(t=>void 0===this.record[t]))return;const e=this.getUuid()||this.getSlug()||String(this.record.id||"");if(!e)return;const r=et(await this.kernel.request(q().page(this.siteRef(),e)));this.setRecord({...this.record,...r})}}let St=null;function bt(){if(!St)throw new Error("Client is not installed.");return St}function $t(t,e){return null!=e&&""!==String(e)?String(e):t.siteRef()}function kt(t,e){e?.page&&e.page>0&&t.set("page",String(Math.floor(e.page))),e?.perPage&&e.perPage>0&&t.set("per_page",String(Math.floor(e.perPage)))}function _t(t){if(null==t)return!1;if("string"==typeof t){const e=t.trim();return""!==e&&"{}"!==e&&"[]"!==e}return Array.isArray(t)?t.length>0:"object"!=typeof t||Object.keys(t).length>0}function jt(t){if(t&&"object"==typeof t)return t.options}function At(t){if("string"==typeof t)return t;if(t&&"object"==typeof t)try{return JSON.stringify(t)}catch{return""}return""}async function vt(t,e){const r=bt(),n=$t(r,e),i=et(await r.request(q().page(n,t)));return r.rememberPage(i),new wt(i,r)}class xt{constructor(t,e=null){this.record=t,this.kernel=e}record;kernel;getTitle(){return new M(this.record.title)}getUrl(){return new U(this.record.url)}getChildren(){return Ct(this.record.children,this.kernel)}isCurrent(t){const e=this.getUrl().path();if(!e)return!1;if(t)return e===t.getUrl().path();const r=this.kernel??Ot,n=r?.snapshot().page;return!(!r||!n)&&e===new wt(n,r).getUrl().path()}getPage(){const t=this.record.page;if(!t||"object"!=typeof t)return null;const e=this.kernel??Ot;return e?new wt(t,e):null}raw(){return{...this.record}}}class Pt{constructor(t,e){this.source=t,this.runtime=e}source;runtime;get record(){return"function"==typeof this.source?this.source():this.source}static async find(t,e){const r=function(){if(!Ot)throw new Error("Client is not installed.");return Ot}(),n=null!=e&&""!==String(e)?String(e):r.siteRef(),i=r.snapshot().menus,s=i[t]||Object.values(i).find(e=>!!e&&(String(e.uuid)===t||String(e.id)===t||String(e.name)===t||String(e.position)===t));if(s)return new Pt(s,r);const o=et(await r.request(q().menu(n,t)));return r.rememberMenu(o),new Pt(o,r)}getName(){return new M(this.record.name)}getPosition(){return String(this.record.position||"")}getItems(){return Ct(this.record.items,this.runtime)}raw(){return{...this.record}}}function Ct(t,e=null){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new xt(t,e)):[]}let Ot=null;class Rt{constructor(t){this.kernel=t}kernel;all(){return function(t,e=function(){return globalThis}()){const r=Array.isArray(t)?t.flatMap(t=>function(t){if(!t||"object"!=typeof t)return[];const e=t,r=Ut(String(e.lang??""));return r?[{lang:r,domain:It(String(e.domain??"")),url:String(e.url??"").trim()}]:[]}(t)):[];return r.length?r.flatMap(t=>{const r=Mt(t.url||function(t,e){const r=e[`locale_${t}_baseurl`];return"string"==typeof r?r.trim():""}(t.lang,e)||t.domain);return t.lang&&r?[{lang:t.lang,domain:t.domain||It(r),url:r}]:[]}):function(t){const e=[];for(const r of Object.keys(t)){const n=/^locale_([a-z]+)_baseurl$/.exec(r);if(!n)continue;const i=Mt(String(t[r]??""));i&&e.push({lang:n[1],domain:It(i),url:i})}return e}(e)}(this.kernel.snapshot().locales)}current(){return Ut(String(this.kernel.snapshot().site?.lang||""))}url(t){const e=Ut(t),r=this.all().find(t=>t.lang===e);return r?.url??""}}function Ut(t){return(t.trim().toLowerCase().replaceAll("_","-").split("-")[0]??"").replace(/[^a-z]/g,"")}function Mt(t){const e=t.trim();return e?(/^https?:\/\//i.test(e)?e:`https://${e.replace(/^\/+/,"")}`).replace(/\/+$/,""):""}function It(t){return t.trim().replace(/^https?:\/\//i,"").replace(/\/.*$/,"")}function Tt(t){return`mc_${(String(t??"").trim().split("/").pop()??"").replace(/^@/,"").replace(/[^A-Za-z0-9]+/g,"_").replace(/^_+|_+$/g,"").toUpperCase()}`}function Nt(t){if("undefined"==typeof window||""===t)return"";const e=window.__MIRO_WEB_PLUGINS__;if(!Array.isArray(e))return"";for(const r of e){const e=String(r??"").trim().toLowerCase(),n=e.lastIndexOf("/");if(n<=0)continue;const i=e.slice(0,n),s=e.slice(n+1);if(""!==i&&(s===t||Wt(s)===t))return i}return""}function Wt(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[^A-Za-z0-9]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()}function Et(t){if("undefined"==typeof window)return{};const e=window[t];return e&&"object"==typeof e?e:{}}function Bt(){const t=ge(),e=function(){try{const t=globalThis.__INERTIA_PAGE__;if(t?.props)return t.props}catch{}return function(){if("undefined"==typeof document)return null;const t=document.querySelector("[data-page]")?.getAttribute("data-page");if(!t)return null;try{return JSON.parse(t).props??null}catch{return null}}()}();return e&&t.hydrate(e),t}function Lt(){const t=Bt();return Ht(t),new wt(()=>t.snapshot().page??{},t)}function qt(){const t=Bt();return Ht(t),new ft(()=>t.snapshot().site??{},t)}function zt(t="topbar"){const e=Bt();return Ht(e),new Pt(()=>e.snapshot().menus[t]??{position:t,items:[]},e)}function Gt(){const t=Bt();return Ht(t),new Rt(t)}function Jt(){return Lt().getAssets()}function Ft(t){return function(t,e){const r=Tt(t),n=function(t){const e=String(t??"").trim();if(e.includes("/")){const[t,...r]=e.split("/");return{vendor:t||"miroart",slug:Wt(r.join("/")||e)}}const r=Wt(e);return{vendor:Nt(r)||"miroart",slug:r}}(t);return new Proxy({name:t,key:r,ready:async()=>async function(t){const e=Date.now();for(;Date.now()-e<4e3;){const e=Et(t);if(Object.keys(e).length)return e;await new Promise(t=>setTimeout(t,50))}return Et(t)}(r),api:()=>Et(r),call:(t,...e)=>{const n=Et(r),i=n[t];if("function"!=typeof i)throw new Error(`Missing plugin method: ${t}`);return i.apply(n,e)},request:async(t="/",r={})=>{const i=q().plugins(n.vendor,n.slug,t||"/"),s=new Headers(r.headers);let o=r.body;return void 0!==r.json&&(o=JSON.stringify(r.json)),et(await e.request(i,{...r,headers:s,body:o}))}},{get(t,e,n){if(e in t)return Reflect.get(t,e,n);if("then"===e||e===Symbol.toStringTag)return;const i=Et(r),s=i[String(e)];return"function"==typeof s?s.bind(i):s},has:(t,e)=>e in t||e in Et(r)})}(t,ge())}function Dt(){const e=ge();return{apiBase:t(()=>e.apiBase()),siteBase:t(()=>e.siteBase()),siteRef:t(()=>e.siteRef())}}function Ht(t){try{const r=function(){try{return Zt??null}catch{return null}}();if(!r)return;const n=r.usePage();t.hydrate(e(n))}catch{}}let Zt=null;function Vt(t){return[...new Set(t)]}function Kt(t,e){const r=new Set(t),n=Vt(e).filter(t=>r.has(t));return Vt(t).forEach((t,e,r)=>{n.includes(t)||n.splice(0===e?0:n.indexOf(r[e-1])+1,0,t)}),n}function Qt(t,e,r){const n=e.filter(e=>r.includes(e)&&t.includes(e)),i=t.filter(t=>!n.includes(t));return n.forEach(t=>{i.splice(Math.min(e.indexOf(t),i.length),0,t)}),i}function Xt(t,e){const r=t?.options,n=Array.isArray(r)?r.find(t=>t?.key===e)?.value:r?.[e];if("string"!=typeof n)return n;try{return JSON.parse(n)}catch{return}}function Yt(){if("undefined"==typeof window)return null;const t=window;return t.__miroOrder??=/* @__PURE__ */new Map,t.__miroOrder}import("@inertiajs/vue3").then(t=>{Zt=t}).catch(()=>{Zt=null});const te=/* @__PURE__ */new Set;function ee(t){te.has(t)||te.add(t)}function re(t,e,r){const n=t.filter(t=>t.type!==c);if(0===n.length)return t;const[i]=n;return n.length>1?(ee(`Slot „${r}” ma kilka korzeni, więc nie da się go przeciągnąć.`),t):i.type===a?Array.isArray(i.children)?t.map(t=>t===i?o(a,{key:i.key??void 0},re(i.children,e,r)):t):t:t.map(t=>t===i?u(i,e):t)}const ne=r({name:"MiroOrder",inheritAttrs:!1,props:{name:String,source:[String,Array],items:Array,at:Function,scope:{type:String,default:"page"},locked:{type:Array,default:()=>[]}},setup(t,{slots:e}){const r=Lt(),c=qt(),u=!0===ge().snapshot().editing,l=()=>"site"===t.scope?c.raw():r.raw(),h=n(null),p=()=>Object.keys(e).filter(t=>"default"!==t&&"$stable"!==t&&!t.startsWith("_")),d=(e,r)=>String(t.at?t.at(e,r):r),g=()=>void 0!==t.items?(()=>{const e=(t.items??[]).map(d);return h.value?Kt(e,h.value):Kt(e,e)})():(()=>{const e=p();return Qt(Kt(e,h.value??(t.name?function(t,e){const r=Xt(t,"miro_order"),n=r&&"object"==typeof r?r[e]:null;return Array.isArray(n)?n.filter(t=>"string"==typeof t):[]}(l(),t.name):[])),e,t.locked)})(),f=(()=>{const e=l()?.id;if(!u||null==e)return null;const r="site"===t.scope?{site:e}:{page:e};if(void 0===t.items)return t.name?{kind:"site"===t.scope?"site_blocks":"page_blocks",...r,name:t.name}:null;const n=t.source?function(t){const e=Array.isArray(t)?t:t.split(".").map(t=>/^\d+$/.test(t)?Number(t):t),[r,...n]=e;return"string"==typeof r&&""!==r?{key:r,path:n}:null}(t.source):null;if(!n)return null;const i=function(t,e,r){let n=Xt(t,e);for(const i of r){if(!n||"object"!=typeof n)return null;n=n[i]}return Array.isArray(n)?n:null}(l(),n.key,n.path);return!i||!t.at&&i.length!==t.items.length?(ee(`Lista „${n.key}” różni się od zapisanej. Podaj :at z indeksem w surowej tablicy.`),null):{kind:"site"===t.scope?"site_option":"page_option",...r,key:n.key,path:n.path}})(),m=f?function(t){return"page_blocks"===t.kind||"site_blocks"===t.kind?`${t.kind}:${"page"in t?t.page:t.site}:${t.name}`:`${t.kind}:${"page"in t?t.page:t.site}:${t.key}:${t.path.join(".")}`}(f):"";if(f){const e={id:m,target:f,keys:g,locked:()=>void 0===t.items?t.locked:[],plan:e=>void 0!==t.items?e:Qt(function(t,e){const r=new Set(e);let n=0;return t.map(t=>r.has(t)?e[n++]:t)}(g(),e),p(),t.locked),apply:t=>{h.value=t}};i(()=>Yt()?.set(m,e)),s(()=>{const t=Yt();t?.get(m)===e&&t.delete(m)})}return()=>{const r=g(),n=void 0!==t.items,i=/* @__PURE__ */new Map;n&&t.items.forEach((t,e)=>i.set(d(t,e),t));const s=r.map((s,c)=>{const u={key:s,index:c,first:0===c,last:c===r.length-1},l=n?e.default:e[s],h=l?.(n?{...u,item:i.get(s)}:u)??[],p=f?re(h,{"data-miro-order-group":m,"data-miro-order-key":s},n?`${t.source}[${s}]`:s):h;return o(a,{key:s},p)});return o(a,null,s)}}}),ie=/[⁢⁤][​‌‍⁠]+⁣/,se={b:"strong",i:"em",u:"u",s:"s"};function oe(t){switch(t.type){case"text":return t.value;case"br":return o("br");case"c":return o("span",{style:{color:`var(--color-${t.value})`}},ae(t.children));case"f":return o("span",{style:{fontFamily:`var(--font-${t.value})`}},ae(t.children));default:return o(se[t.type],ae(t.children))}}function ae(t){return t.map(oe)}const ce=t=>{const e=l(t.value),r=ie.test(e);if(!r&&!function(t){return t.includes("[")||t.includes("\n")}(e))return e;const n=ae(y(e));return r?o("span",{"data-miro-rich":"",style:{display:"contents"}},n):1===n.length?n[0]:n};ce.props=["value"],ce.displayName="MiroText";class ue{snap={page:null,site:null,menus:{},locales:[],seo:null,options:{},editing:!1};options;inflight=/* @__PURE__ */new Map;cache=/* @__PURE__ */new Map;constructor(t={}){this.options=t,t.page&&this.hydrate(t.page),St=this,mt=this,Ot=this}hydrate(t){return this.snap=rt(this.snap,function(t){const e={page:null,site:null,menus:{},locales:[],seo:null,options:{},editing:!1};if(!t||"object"!=typeof t)return e;const r=t,n=nt(r.props)?r.props:r;e.page=it(n.page),e.site=it(n.site),e.seo=nt(n.seo)?n.seo:null,e.options=nt(n.options)?n.options:{},e.locales=Array.isArray(n.locales)?n.locales:[],e.editing=void 0!==n.miroEdit&&null!==n.miroEdit;const i=n.menus;if(nt(i))for(const[s,o]of Object.entries(i))e.menus[s]=it(o);return e}(t)),this.snap}snapshot(){return this.snap}apiBase(){return function(t){if(t)return String(t).replace(/\/+$/,"");const e=tt();return e.apiBase?String(e.apiBase).replace(/\/+$/,""):function(){if("undefined"==typeof location)return"";const t=String(location.origin||"").replace(/\/+$/,"");if(t&&"null"!==t)return t;const e=location.hostname||"";return e?`${location.protocol}//${e}`:""}()}(this.options.apiBase)}siteBase(){return function(t){if(t)return String(t).replace(/\/+$/,"");const e=tt();return e.siteBase?String(e.siteBase).replace(/\/+$/,""):"undefined"!=typeof location?location.origin:""}(this.options.siteBase)}siteRef(){return null!=this.options.site&&""!==String(this.options.site)?String(this.options.site):ot(this.snap.site)}async request(t,e={}){const r=String(e.method||"GET").toUpperCase(),n=`${r} ${t}`;if("GET"===r&&this.cache.has(n))return this.cache.get(n);if("GET"===r){const t=this.inflight.get(n);if(t)return t}const i=this.apiBase();if(!i)throw new Error("Remote origin is not configured.");const s=async function(t,e,r={}){const{fetchImpl:n,...i}=r,s=e.startsWith("http")?e:L(t,e),o=n??fetch,a=new Headers(i.headers);a.has("Accept")||a.set("Accept","application/json");const c=await o(s,{...i,headers:a}),u=await c.text();let l=null;if(u)try{l=JSON.parse(u)}catch{l={message:u}}if(!c.ok){const t=new Error(`Request failed (${c.status})`);throw t.status=c.status,t.body=l,t}return l}(i,t,{...e,fetchImpl:this.options.fetch}).then(t=>("GET"===r&&this.cache.set(n,t),t));return"GET"===r&&(this.inflight.set(n,s),s.finally(()=>{this.inflight.delete(n)}).catch(()=>{})),s}rememberPage(t){const e=this.snap.page;e&&String(e.id)===String(t.id)&&(this.snap=rt(this.snap,{page:{...e,...t}}))}rememberSite(t){this.snap=rt(this.snap,{site:{...this.snap.site??{},...t}})}rememberMenu(t){const e=String(t.position||t.uuid||t.id||t.name||"menu");this.snap=rt(this.snap,{menus:{[e]:t}})}}let le=null;function he(t={}){return le=new ue(t),le}function pe(){return le||(le=new ue),le}const de=/* @__PURE__ */Symbol.for("miro.client");function ge(){return h(de,null)??pe()}function fe(t={}){return{install(e,r={}){const n=he({...t,...r});e.provide(de,n),e.component("MiroText",ce),e.component("MiroOrder",ne),function(t){import("@inertiajs/vue3").then(e=>{const r=e.router;r?.page&&t.hydrate(r.page),r?.on?.("success",e=>{const r=e?.detail?.page;r&&t.hydrate(r)}),r?.on?.("navigate",e=>{const r=e?.detail?.page;r&&t.hydrate(r)})}).catch(()=>{})}(n)}}}const me=fe(),ye=me;export{V as Asset,I as AssetName,ct as CollectionCard,K as Gallery,Rt as Locales,Pt as Menu,xt as MenuItem,M as MenuTitle,me as Miro,ne as MiroOrder,ce as MiroText,R as OptionValue,wt as Page,P as PageContent,v as PageSmallTitle,A as PageSubtitle,x as PageSummary,j as PageTitle,p as RICH_COLORS,d as RICH_FONTS,de as SDK_KEY,N as SeoDescription,T as SeoTitle,ft as Site,O as SiteName,C as SiteTitle,_ as TextValue,U as UrlValue,fe as createMiro,he as createRuntime,ye as default,pe as getRuntime,y as parseRichText,S as plainText,Tt as pluginWindowKey,ge as useKernel,Jt as useMiroAssets,Dt as useMiroConfig,Gt as useMiroLocales,zt as useMiroMenu,Lt as useMiroPage,qt as useMiroSite,Ft as usePlugin};
@@ -0,0 +1,54 @@
1
+ import type { PageRecord, SiteRecord } from "./types";
2
+ /** Opcja strony lub site z kolejnością stałych bloków: `{ "home": ["hero", "faq"] }`. */
3
+ export declare const ORDER_OPTION = "miro_order";
4
+ export type OrderPathPart = string | number;
5
+ export type OrderTarget = {
6
+ kind: "page_blocks";
7
+ page: number | string;
8
+ name: string;
9
+ } | {
10
+ kind: "site_blocks";
11
+ site: number | string;
12
+ name: string;
13
+ } | {
14
+ kind: "page_option";
15
+ page: number | string;
16
+ key: string;
17
+ path: OrderPathPart[];
18
+ } | {
19
+ kind: "site_option";
20
+ site: number | string;
21
+ key: string;
22
+ path: OrderPathPart[];
23
+ };
24
+ /** Grupa w ramce edytora. Nakładka czyta ją z `window.__miroOrder`, więc kontrakt nie może się rozjechać. */
25
+ export type OrderGroup = {
26
+ id: string;
27
+ target: OrderTarget;
28
+ /** Wszystkie klucze w obecnej kolejności, także ukrytych bloków. */
29
+ keys: () => string[];
30
+ locked: () => string[];
31
+ /** Nowa kolejność elementów widocznych → lista do zapisu i do `apply`. */
32
+ plan: (shown: string[]) => string[];
33
+ /** Vue przestawia od razu. `null` wraca do kolejności z danych. */
34
+ apply: (keys: string[] | null) => void;
35
+ };
36
+ /**
37
+ * Zapisana kolejność + klucze z szablonu. Klucza, którego szablon już nie ma, nie rysujemy.
38
+ * Nowy klucz staje za swoim poprzednikiem z szablonu, a pierwszy w szablonie idzie na początek.
39
+ */
40
+ export declare function mergeOrder(declared: string[], stored: string[]): string[];
41
+ /** Zablokowany klucz stoi tam, gdzie w szablonie (np. baner z H1 zawsze pierwszy). */
42
+ export declare function pinLocked(order: string[], declared: string[], locked: string[]): string[];
43
+ /** Widoczne klucze w nowej kolejności wchodzą w miejsca, które razem zajmowały. Ukryte stoją. */
44
+ export declare function fillShown(all: string[], shown: string[]): string[];
45
+ export declare function storedOrder(record: PageRecord | SiteRecord | null | undefined, name: string): string[];
46
+ /** `gallery.albums` albo `['gallery', 'albums', 3, 'photos']` → klucz opcji i ścieżka w jej JSON-ie. */
47
+ export declare function parseSource(source: string | OrderPathPart[]): {
48
+ key: string;
49
+ path: OrderPathPart[];
50
+ } | null;
51
+ /** Tablica pod ścieżką w opcji albo `null`, gdy jej nie ma. */
52
+ export declare function sourceList(record: PageRecord | SiteRecord | null | undefined, key: string, path: OrderPathPart[]): unknown[] | null;
53
+ export declare function orderGroupId(target: OrderTarget): string;
54
+ export declare function orderRegistry(): Map<string, OrderGroup> | null;
package/dist/types.d.ts CHANGED
@@ -84,6 +84,8 @@ export type Snapshot = {
84
84
  locales: unknown[];
85
85
  seo: Dict | null;
86
86
  options: Dict;
87
+ /** Prop `miroEdit`: strona jest w ramce edytora wizualnego. */
88
+ editing: boolean;
87
89
  };
88
90
  export type ClientOptions = {
89
91
  apiBase?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miroart/sdk",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Vue 3 client for preloaded page data and a remote JSON origin.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",