@forsakringskassan/docs-live-example 1.4.0 → 1.4.2

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.
@@ -32,7 +32,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
32
32
 
33
33
  // node_modules/highlight.js/lib/core.js
34
34
  var require_core = __commonJS({
35
- "node_modules/highlight.js/lib/core.js"(exports2, module2) {
35
+ "node_modules/highlight.js/lib/core.js"(exports, module2) {
36
36
  function deepFreeze(obj) {
37
37
  if (obj instanceof Map) {
38
38
  obj.clear = obj.delete = obj.set = function() {
@@ -1620,10 +1620,152 @@ __export(src_exports, {
1620
1620
  module.exports = __toCommonJS(src_exports);
1621
1621
 
1622
1622
  // sfc-script:/home/runner/work/docs-live-example/docs-live-example/src/LiveExample.vue?type=script
1623
+ var import_vue5 = require("vue");
1624
+
1625
+ // sfc-script:/home/runner/work/docs-live-example/docs-live-example/src/LiveExampleSourcecode.vue?type=script
1626
+ var import_vue = require("vue");
1623
1627
  var import_vue2 = require("vue");
1624
1628
 
1629
+ // src/expand-animation.ts
1630
+ var DURATION = 400;
1631
+ var ClassNames = {
1632
+ EXPANDING: "expanding",
1633
+ COLLAPSING: "collapsing"
1634
+ };
1635
+ var prefersReducedMotion = window.matchMedia("(prefers-reduced-motion)");
1636
+ var useAnimation = !prefersReducedMotion.matches;
1637
+ prefersReducedMotion.addEventListener("change", (event) => {
1638
+ useAnimation = !event.matches;
1639
+ });
1640
+ function expandAnimation(element) {
1641
+ let animation = null;
1642
+ let isOpen = false;
1643
+ let isClosing = false;
1644
+ let isExpanding = false;
1645
+ return {
1646
+ get isOpen() {
1647
+ return isOpen;
1648
+ },
1649
+ toggle() {
1650
+ if (useAnimation) {
1651
+ element.style.overflow = "hidden";
1652
+ if (isExpanding || isOpen) {
1653
+ isOpen = false;
1654
+ shrink();
1655
+ } else if (isClosing || !isOpen) {
1656
+ isOpen = true;
1657
+ open();
1658
+ }
1659
+ return;
1660
+ }
1661
+ if (isOpen) {
1662
+ isOpen = false;
1663
+ element.setAttribute("aria-expanded", "false");
1664
+ } else {
1665
+ isOpen = true;
1666
+ element.setAttribute("aria-expanded", "true");
1667
+ }
1668
+ }
1669
+ };
1670
+ function shrink() {
1671
+ isClosing = true;
1672
+ const startHeight = `${element.offsetHeight}px`;
1673
+ const endHeight = `0px`;
1674
+ element.classList.add(ClassNames.COLLAPSING);
1675
+ if (animation) {
1676
+ animation.cancel();
1677
+ }
1678
+ animation = element.animate(
1679
+ {
1680
+ height: [startHeight, endHeight]
1681
+ },
1682
+ {
1683
+ duration: DURATION,
1684
+ easing: "ease-in-out"
1685
+ }
1686
+ );
1687
+ animation.onfinish = () => {
1688
+ onAnimationFinish(false);
1689
+ };
1690
+ animation.oncancel = () => {
1691
+ element.classList.remove(ClassNames.COLLAPSING);
1692
+ isClosing = false;
1693
+ };
1694
+ }
1695
+ function open() {
1696
+ let currentHeight = 0;
1697
+ if (animation) {
1698
+ currentHeight = element.getBoundingClientRect().height;
1699
+ }
1700
+ element.setAttribute("aria-expanded", "true");
1701
+ window.requestAnimationFrame(() => expand(currentHeight));
1702
+ }
1703
+ function expand(currentHeight) {
1704
+ isExpanding = true;
1705
+ if (animation) {
1706
+ animation.cancel();
1707
+ element.style.height = "";
1708
+ }
1709
+ const startHeight = `${currentHeight}px`;
1710
+ const endHeight = `${element.offsetHeight}px`;
1711
+ element.classList.add(ClassNames.EXPANDING);
1712
+ animation = element.animate(
1713
+ {
1714
+ height: [startHeight, endHeight]
1715
+ },
1716
+ {
1717
+ duration: DURATION,
1718
+ easing: "ease-in-out"
1719
+ }
1720
+ );
1721
+ animation.onfinish = () => {
1722
+ onAnimationFinish(true);
1723
+ };
1724
+ animation.oncancel = () => {
1725
+ element.classList.remove(ClassNames.EXPANDING);
1726
+ isExpanding = false;
1727
+ };
1728
+ }
1729
+ function onAnimationFinish(open2) {
1730
+ element.setAttribute("aria-expanded", open2 ? "true" : "false");
1731
+ animation = null;
1732
+ isClosing = false;
1733
+ isExpanding = false;
1734
+ element.classList.remove(ClassNames.EXPANDING);
1735
+ element.classList.remove(ClassNames.COLLAPSING);
1736
+ element.style.height = "";
1737
+ element.style.overflow = "";
1738
+ }
1739
+ }
1740
+
1741
+ // src/utils/generate-id.ts
1742
+ function cyrb53(str) {
1743
+ const a = 2654435761;
1744
+ const b = 1597334677;
1745
+ const c = 2246822507;
1746
+ const d = 3266489909;
1747
+ const e = 4294967296;
1748
+ const f = 2097151;
1749
+ const seed = 0;
1750
+ let h1 = 3735928559 ^ seed;
1751
+ let h2 = 1103547991 ^ seed;
1752
+ for (let i = 0, ch; i < str.length; i++) {
1753
+ ch = str.charCodeAt(i);
1754
+ h1 = Math.imul(h1 ^ ch, a);
1755
+ h2 = Math.imul(h2 ^ ch, b);
1756
+ }
1757
+ h1 = Math.imul(h1 ^ h1 >>> 16, c) ^ Math.imul(h2 ^ h2 >>> 13, d);
1758
+ h2 = Math.imul(h2 ^ h2 >>> 16, c) ^ Math.imul(h1 ^ h1 >>> 13, d);
1759
+ return e * (f & h2) + (h1 >>> 0);
1760
+ }
1761
+ function generateId(template) {
1762
+ const hash = cyrb53(template);
1763
+ return `le-${hash.toString(16)}`;
1764
+ }
1765
+
1625
1766
  // src/utils/highlight.ts
1626
- var prettier = __toESM(require("prettier"));
1767
+ var import_standalone = __toESM(require("prettier/standalone"));
1768
+ var import_parser_html = __toESM(require("prettier/parser-html"));
1627
1769
 
1628
1770
  // node_modules/highlight.js/es/core.js
1629
1771
  var import_core = __toESM(require_core(), 1);
@@ -1859,13 +2001,14 @@ function xml(hljs) {
1859
2001
  core_default.registerLanguage("html", xml);
1860
2002
  var prettierConfig = {
1861
2003
  parser: "html",
2004
+ plugins: [import_parser_html.default],
1862
2005
  singleQuote: false,
1863
2006
  arrowParens: "always",
1864
2007
  tabWidth: 4,
1865
2008
  printWidth: 80
1866
2009
  };
1867
2010
  async function highlight(code) {
1868
- const formatted = await prettier.format(code, prettierConfig);
2011
+ const formatted = await import_standalone.default.format(code, prettierConfig);
1869
2012
  const { value } = core_default.highlight(formatted, { language: "html" });
1870
2013
  return `<code class="hljs lang-html" tabindex="0">${value}</code>`;
1871
2014
  }
@@ -1876,10 +2019,224 @@ function stripComments(html) {
1876
2019
  return html.replace(commentPattern, "");
1877
2020
  }
1878
2021
 
1879
- // src/LiveCode.ts
1880
- var import_vue = require("vue");
1881
- var LiveCode_default = (0, import_vue.defineComponent)({
1882
- name: "LiveCode",
2022
+ // src/utils/get-source-code.ts
2023
+ async function getSourceCode(options) {
2024
+ const { language, template, element } = options;
2025
+ if (language === "original") {
2026
+ return await highlight(template);
2027
+ } else {
2028
+ const html = element.innerHTML;
2029
+ const uncommented = stripComments(html);
2030
+ return await highlight(uncommented);
2031
+ }
2032
+ }
2033
+
2034
+ // sfc-script:/home/runner/work/docs-live-example/docs-live-example/src/LiveExampleSourcecode.vue?type=script
2035
+ var LiveExampleSourcecode_default = /* @__PURE__ */ (0, import_vue.defineComponent)({
2036
+ __name: "LiveExampleSourcecode",
2037
+ props: {
2038
+ element: {
2039
+ type: HTMLElement,
2040
+ required: true
2041
+ },
2042
+ template: {
2043
+ type: String,
2044
+ required: true
2045
+ },
2046
+ templateLanguage: {
2047
+ type: String,
2048
+ required: true
2049
+ }
2050
+ },
2051
+ setup(__props, { expose: __expose }) {
2052
+ __expose();
2053
+ const props = __props;
2054
+ let idPrefix = generateId(props.template);
2055
+ const sourcecode = (0, import_vue2.ref)("");
2056
+ const expandable = (0, import_vue2.ref)(null);
2057
+ const animation = (0, import_vue2.ref)({
2058
+ isOpen: false,
2059
+ toggle() {
2060
+ }
2061
+ });
2062
+ const selectedLanguage = (0, import_vue2.ref)(toSelectedLanguage(props.templateLanguage));
2063
+ const codeToggleText = (0, import_vue2.computed)(() => {
2064
+ return animation.value.isOpen ? "D\xF6lj kod" : "Visa kod";
2065
+ });
2066
+ (0, import_vue2.onMounted)(() => {
2067
+ if (expandable.value) {
2068
+ animation.value = expandAnimation(expandable.value);
2069
+ } else {
2070
+ throw new Error("Missing HTML element");
2071
+ }
2072
+ updateSourcecode();
2073
+ });
2074
+ (0, import_vue2.watch)(() => props.template, onUpdateTemplate);
2075
+ (0, import_vue2.watch)(() => props.templateLanguage, updateSelectedLanguage, { once: true });
2076
+ async function updateSourcecode() {
2077
+ await (0, import_vue2.nextTick)();
2078
+ sourcecode.value = await getSourceCode({
2079
+ language: selectedLanguage.value,
2080
+ template: props.template ?? "",
2081
+ element: unwrapElement(props.element)
2082
+ });
2083
+ }
2084
+ function unwrapElement(element) {
2085
+ const firstElementChild = element.firstElementChild;
2086
+ return firstElementChild ?? element;
2087
+ }
2088
+ function updateSelectedLanguage(value) {
2089
+ selectedLanguage.value = toSelectedLanguage(value);
2090
+ }
2091
+ function id(suffix) {
2092
+ return `${idPrefix}--${suffix}`;
2093
+ }
2094
+ function toSelectedLanguage(value) {
2095
+ return value === "html" ? "rendered" : "original";
2096
+ }
2097
+ function onUpdateTemplate(template) {
2098
+ idPrefix = generateId(template);
2099
+ updateSourcecode();
2100
+ }
2101
+ function onToggleCode() {
2102
+ animation.value.toggle();
2103
+ }
2104
+ const __returned__ = { props, get idPrefix() {
2105
+ return idPrefix;
2106
+ }, set idPrefix(v) {
2107
+ idPrefix = v;
2108
+ }, sourcecode, expandable, animation, selectedLanguage, codeToggleText, updateSourcecode, unwrapElement, updateSelectedLanguage, id, toSelectedLanguage, onUpdateTemplate, onToggleCode };
2109
+ Object.defineProperty(__returned__, "__isScriptSetup", { enumerable: false, value: true });
2110
+ return __returned__;
2111
+ }
2112
+ });
2113
+
2114
+ // sfc-template:/home/runner/work/docs-live-example/docs-live-example/src/LiveExampleSourcecode.vue?type=template
2115
+ var import_vue3 = require("vue");
2116
+ var _withScopeId = (n) => ((0, import_vue3.pushScopeId)("data-v-7a98eb26"), n = n(), (0, import_vue3.popScopeId)(), n);
2117
+ var _hoisted_1 = { class: "live-example__code-toggle" };
2118
+ var _hoisted_2 = ["aria-controls", "aria-expanded"];
2119
+ var _hoisted_3 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ (0, import_vue3.createElementVNode)(
2120
+ "i",
2121
+ { class: "icon icon--code" },
2122
+ null,
2123
+ -1
2124
+ /* HOISTED */
2125
+ ));
2126
+ var _hoisted_4 = ["id"];
2127
+ var _hoisted_5 = {
2128
+ class: "live-example__code-languages",
2129
+ onsubmit: "event.preventDefault()"
2130
+ };
2131
+ var _hoisted_6 = {
2132
+ key: 0,
2133
+ class: "fieldset radio-button-group radio-button-group--horizontal"
2134
+ };
2135
+ var _hoisted_7 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ (0, import_vue3.createElementVNode)(
2136
+ "legend",
2137
+ { class: "label fieldset__label" },
2138
+ "Kodspr\xE5k",
2139
+ -1
2140
+ /* HOISTED */
2141
+ ));
2142
+ var _hoisted_8 = { class: "fieldset__content radio-button-group__content" };
2143
+ var _hoisted_9 = {
2144
+ key: 0,
2145
+ class: "radio-button"
2146
+ };
2147
+ var _hoisted_10 = ["id"];
2148
+ var _hoisted_11 = ["for"];
2149
+ var _hoisted_12 = { class: "radio-button" };
2150
+ var _hoisted_13 = ["id"];
2151
+ var _hoisted_14 = ["for"];
2152
+ var _hoisted_15 = ["innerHTML"];
2153
+ function render(_ctx, _cache, $props, $setup, $data, $options) {
2154
+ return (0, import_vue3.openBlock)(), (0, import_vue3.createElementBlock)(
2155
+ import_vue3.Fragment,
2156
+ null,
2157
+ [
2158
+ (0, import_vue3.createElementVNode)("div", _hoisted_1, [
2159
+ (0, import_vue3.createElementVNode)("button", {
2160
+ type: "button",
2161
+ class: "button button--discrete",
2162
+ "aria-controls": $setup.id("code-expand"),
2163
+ "aria-expanded": $setup.animation.isOpen ? "true" : "false",
2164
+ onClick: $setup.onToggleCode
2165
+ }, [
2166
+ _hoisted_3,
2167
+ (0, import_vue3.createTextVNode)(
2168
+ " " + (0, import_vue3.toDisplayString)($setup.codeToggleText),
2169
+ 1
2170
+ /* TEXT */
2171
+ )
2172
+ ], 8, _hoisted_2)
2173
+ ]),
2174
+ (0, import_vue3.createElementVNode)("div", {
2175
+ id: $setup.id("code-expand"),
2176
+ ref: "expandable",
2177
+ class: "collapsed"
2178
+ }, [
2179
+ (0, import_vue3.createCommentVNode)(" [html-validate-disable-next wcag/h32 -- this form is not meant to be submitted] "),
2180
+ (0, import_vue3.createElementVNode)("form", _hoisted_5, [
2181
+ $setup.sourcecode ? ((0, import_vue3.openBlock)(), (0, import_vue3.createElementBlock)("fieldset", _hoisted_6, [
2182
+ _hoisted_7,
2183
+ (0, import_vue3.createElementVNode)("div", _hoisted_8, [
2184
+ $props.templateLanguage === "vue" ? ((0, import_vue3.openBlock)(), (0, import_vue3.createElementBlock)("div", _hoisted_9, [
2185
+ (0, import_vue3.withDirectives)((0, import_vue3.createElementVNode)("input", {
2186
+ id: $setup.id("lang-original"),
2187
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => $setup.selectedLanguage = $event),
2188
+ type: "radio",
2189
+ class: "radio-button__input",
2190
+ name: "selected-language",
2191
+ value: "original",
2192
+ onChange: $setup.updateSourcecode
2193
+ }, null, 40, _hoisted_10), [
2194
+ [import_vue3.vModelRadio, $setup.selectedLanguage]
2195
+ ]),
2196
+ (0, import_vue3.createElementVNode)("label", {
2197
+ for: $setup.id("lang-original"),
2198
+ class: "radio-button__label"
2199
+ }, " Vue ", 8, _hoisted_11)
2200
+ ])) : (0, import_vue3.createCommentVNode)("v-if", true),
2201
+ (0, import_vue3.createElementVNode)("div", _hoisted_12, [
2202
+ (0, import_vue3.withDirectives)((0, import_vue3.createElementVNode)("input", {
2203
+ id: $setup.id("lang-rendered"),
2204
+ "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => $setup.selectedLanguage = $event),
2205
+ type: "radio",
2206
+ class: "radio-button__input",
2207
+ name: "selected-language",
2208
+ value: "rendered",
2209
+ onChange: $setup.updateSourcecode
2210
+ }, null, 40, _hoisted_13), [
2211
+ [import_vue3.vModelRadio, $setup.selectedLanguage]
2212
+ ]),
2213
+ (0, import_vue3.createElementVNode)("label", {
2214
+ for: $setup.id("lang-rendered"),
2215
+ class: "radio-button__label"
2216
+ }, " HTML ", 8, _hoisted_14)
2217
+ ])
2218
+ ])
2219
+ ])) : (0, import_vue3.createCommentVNode)("v-if", true)
2220
+ ]),
2221
+ (0, import_vue3.createCommentVNode)(" eslint-disable-next-line vue/no-v-html -- expected to show highlighted markup "),
2222
+ (0, import_vue3.createElementVNode)("pre", { innerHTML: $setup.sourcecode }, null, 8, _hoisted_15)
2223
+ ], 8, _hoisted_4)
2224
+ ],
2225
+ 64
2226
+ /* STABLE_FRAGMENT */
2227
+ );
2228
+ }
2229
+
2230
+ // src/LiveExampleSourcecode.vue
2231
+ LiveExampleSourcecode_default.render = render;
2232
+ LiveExampleSourcecode_default.__file = "src/LiveExampleSourcecode.vue";
2233
+ LiveExampleSourcecode_default.__scopeId = "data-v-7a98eb26";
2234
+ var LiveExampleSourcecode_default2 = LiveExampleSourcecode_default;
2235
+
2236
+ // src/live-vue-code.ts
2237
+ var import_vue4 = require("vue");
2238
+ var live_vue_code_default = (0, import_vue4.defineComponent)({
2239
+ name: "LiveVueCode",
1883
2240
  props: {
1884
2241
  template: {
1885
2242
  type: String,
@@ -1899,8 +2256,12 @@ var LiveCode_default = (0, import_vue.defineComponent)({
1899
2256
  }
1900
2257
  },
1901
2258
  render() {
1902
- const renderFunction = (0, import_vue.compile)(this.template);
1903
- return (0, import_vue.h)(
2259
+ const renderFunction = (0, import_vue4.compile)(this.template);
2260
+ if (!renderFunction) {
2261
+ const message = "Failed to compile Vue render function!";
2262
+ return (0, import_vue4.h)("div", { style: "color: red" }, message);
2263
+ }
2264
+ return (0, import_vue4.h)(
1904
2265
  {
1905
2266
  name: "LiveComponent",
1906
2267
  data() {
@@ -1925,124 +2286,32 @@ var LiveCode_default = (0, import_vue.defineComponent)({
1925
2286
  }
1926
2287
  });
1927
2288
 
1928
- // src/expand-animation.ts
1929
- var DURATION = 400;
1930
- var ClassNames = {
1931
- EXPANDING: "expanding",
1932
- COLLAPSING: "collapsing"
1933
- };
1934
- var prefersReducedMotion = window.matchMedia("(prefers-reduced-motion)");
1935
- var useAnimation = !prefersReducedMotion.matches;
1936
- prefersReducedMotion.addEventListener("change", (event) => {
1937
- useAnimation = !event.matches;
1938
- });
1939
- function expandAnimation(element) {
1940
- let animation = null;
1941
- let isOpen = false;
1942
- let isClosing = false;
1943
- let isExpanding = false;
1944
- return {
1945
- get isOpen() {
1946
- return isOpen;
1947
- },
1948
- toggle() {
1949
- if (useAnimation) {
1950
- element.style.overflow = "hidden";
1951
- if (isExpanding || isOpen) {
1952
- isOpen = false;
1953
- shrink();
1954
- } else if (isClosing || !isOpen) {
1955
- isOpen = true;
1956
- open();
1957
- }
1958
- return;
1959
- }
1960
- if (isOpen) {
1961
- isOpen = false;
1962
- element.setAttribute("aria-expanded", "false");
1963
- } else {
1964
- isOpen = true;
1965
- element.setAttribute("aria-expanded", "true");
1966
- }
1967
- }
1968
- };
1969
- function shrink() {
1970
- isClosing = true;
1971
- const startHeight = `${element.offsetHeight}px`;
1972
- const endHeight = `0px`;
1973
- element.classList.add(ClassNames.COLLAPSING);
1974
- if (animation) {
1975
- animation.cancel();
1976
- }
1977
- animation = element.animate(
1978
- {
1979
- height: [startHeight, endHeight]
1980
- },
1981
- {
1982
- duration: DURATION,
1983
- easing: "ease-in-out"
1984
- }
1985
- );
1986
- animation.onfinish = () => {
1987
- onAnimationFinish(false);
1988
- };
1989
- animation.oncancel = () => {
1990
- element.classList.remove(ClassNames.COLLAPSING);
1991
- isClosing = false;
1992
- };
1993
- }
1994
- function open() {
1995
- let currentHeight = 0;
1996
- if (animation) {
1997
- currentHeight = element.getBoundingClientRect().height;
1998
- }
1999
- element.setAttribute("aria-expanded", "true");
2000
- window.requestAnimationFrame(() => expand(currentHeight));
2001
- }
2002
- function expand(currentHeight) {
2003
- isExpanding = true;
2004
- if (animation) {
2005
- animation.cancel();
2006
- element.style.height = "";
2007
- }
2008
- const startHeight = `${currentHeight}px`;
2009
- const endHeight = `${element.offsetHeight}px`;
2010
- element.classList.add(ClassNames.EXPANDING);
2011
- animation = element.animate(
2012
- {
2013
- height: [startHeight, endHeight]
2014
- },
2015
- {
2016
- duration: DURATION,
2017
- easing: "ease-in-out"
2018
- }
2019
- );
2020
- animation.onfinish = () => {
2021
- onAnimationFinish(true);
2022
- };
2023
- animation.oncancel = () => {
2024
- element.classList.remove(ClassNames.EXPANDING);
2025
- isExpanding = false;
2026
- };
2027
- }
2028
- function onAnimationFinish(open2) {
2029
- element.setAttribute("aria-expanded", open2 ? "true" : "false");
2030
- animation = null;
2031
- isClosing = false;
2032
- isExpanding = false;
2033
- element.classList.remove(ClassNames.EXPANDING);
2034
- element.classList.remove(ClassNames.COLLAPSING);
2035
- element.style.height = "";
2036
- element.style.overflow = "";
2037
- }
2038
- }
2039
-
2040
2289
  // sfc-script:/home/runner/work/docs-live-example/docs-live-example/src/LiveExample.vue?type=script
2041
- var idCounter = 1;
2042
- var LiveExample_default = (0, import_vue2.defineComponent)({
2290
+ var LiveExample_default = (0, import_vue5.defineComponent)({
2043
2291
  name: "LiveExample",
2044
- components: { LiveCode: LiveCode_default },
2292
+ components: { LiveExampleSourcecode: LiveExampleSourcecode_default2, LiveVueCode: live_vue_code_default },
2045
2293
  props: {
2294
+ /**
2295
+ * Explicitly render example in given language.
2296
+ *
2297
+ * Must be one of:
2298
+ *
2299
+ * - `"vue"` - Interpret `template` as a Vue SFC.
2300
+ * - `"html"` - Interpret `template` as vanilla HTML.
2301
+ *
2302
+ * Default is `"auto"` but you should not explicitly set this value
2303
+ * yourself. When set to `"auto"` the contents of `template` prop will
2304
+ * be autodetected based on some heurestics (subject to change at any
2305
+ * time).
2306
+ */
2307
+ language: {
2308
+ type: String,
2309
+ required: false,
2310
+ default: "auto",
2311
+ validator(value) {
2312
+ return ["vue", "html", "auto"].includes(value);
2313
+ }
2314
+ },
2046
2315
  template: {
2047
2316
  type: String,
2048
2317
  required: true
@@ -2071,220 +2340,100 @@ var LiveExample_default = (0, import_vue2.defineComponent)({
2071
2340
  },
2072
2341
  data() {
2073
2342
  return {
2074
- idPrefix: `live-example-${idCounter++}`,
2075
- codeLanguage: "html",
2076
- codeExpand: {
2077
- isOpen: false,
2078
- toggle() {
2079
- }
2080
- }
2343
+ /** Language declared by parent element via `data-language`, if any */
2344
+ parentLanguage: "",
2345
+ exampleElement: void 0
2081
2346
  };
2082
2347
  },
2083
2348
  computed: {
2084
- isVue() {
2085
- return Object.keys(this.components).length > 0;
2086
- },
2087
- codeToggleText() {
2088
- return this.codeExpand.isOpen ? "D\xF6lj kod" : "Visa kod";
2089
- },
2090
- exampleElement() {
2091
- return this.$refs.example;
2092
- },
2093
- expandableElement() {
2094
- return this.$refs.expandable;
2095
- },
2096
- templateElement() {
2097
- return this.$refs.template;
2098
- }
2099
- },
2100
- watch: {
2101
- template: {
2102
- immediate: false,
2103
- handler() {
2104
- this.compileCode();
2349
+ templateLanguage() {
2350
+ if (this.language !== "auto") {
2351
+ return this.language;
2105
2352
  }
2106
- },
2107
- codeLanguage: {
2108
- immediate: false,
2109
- handler() {
2110
- this.compileCode();
2353
+ if (this.parentLanguage) {
2354
+ return this.parentLanguage;
2111
2355
  }
2356
+ const hasChildComponents = Object.keys(this.components).length > 0;
2357
+ return hasChildComponents ? "vue" : "html";
2112
2358
  }
2113
2359
  },
2114
2360
  mounted() {
2115
- if (this.isVue) {
2116
- this.codeLanguage = "vue";
2117
- }
2118
- this.codeExpand = expandAnimation(this.expandableElement);
2119
- this.compileCode();
2120
- },
2121
- methods: {
2122
- onToggleCode() {
2123
- this.codeExpand.toggle();
2124
- },
2125
- compileCode() {
2126
- switch (this.codeLanguage) {
2127
- case "vue":
2128
- this.compileVue();
2129
- break;
2130
- case "html":
2131
- this.compileHTML();
2132
- break;
2133
- }
2134
- },
2135
- async compileVue() {
2136
- const { templateElement } = this;
2137
- templateElement.innerHTML = await highlight(this.template);
2138
- },
2139
- async compileHTML() {
2140
- await this.$nextTick();
2141
- const { exampleElement, templateElement } = this;
2142
- const html = exampleElement.innerHTML;
2143
- const uncommented = stripComments(html);
2144
- templateElement.innerHTML = await highlight(uncommented);
2361
+ const parent = this.$el.closest("[data-language]");
2362
+ if (parent) {
2363
+ this.parentLanguage = parent.dataset.language ?? "";
2145
2364
  }
2365
+ this.exampleElement = this.$refs.example;
2146
2366
  }
2147
2367
  });
2148
2368
 
2149
2369
  // sfc-template:/home/runner/work/docs-live-example/docs-live-example/src/LiveExample.vue?type=template
2150
- var import_vue3 = require("vue");
2151
- var _withScopeId = (n) => ((0, import_vue3.pushScopeId)("data-v-f5e7ab48"), n = n(), (0, import_vue3.popScopeId)(), n);
2152
- var _hoisted_1 = { class: "live-example__container" };
2153
- var _hoisted_2 = {
2370
+ var import_vue6 = require("vue");
2371
+ var _hoisted_16 = { class: "live-example__container" };
2372
+ var _hoisted_22 = {
2154
2373
  ref: "example",
2155
2374
  class: "live-example__example"
2156
2375
  };
2157
- var _hoisted_3 = { class: "live-example__controls" };
2158
- var _hoisted_4 = { class: "live-example__code" };
2159
- var _hoisted_5 = { class: "live-example__code-toggle" };
2160
- var _hoisted_6 = ["aria-controls", "aria-expanded"];
2161
- var _hoisted_7 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ (0, import_vue3.createElementVNode)(
2162
- "i",
2163
- { class: "icon icon--code" },
2376
+ var _hoisted_32 = { key: 0 };
2377
+ var _hoisted_42 = ["innerHTML"];
2378
+ var _hoisted_52 = { key: 2 };
2379
+ var _hoisted_62 = /* @__PURE__ */ (0, import_vue6.createElementVNode)(
2380
+ "pre",
2164
2381
  null,
2382
+ "Unknown language, cannot render example",
2165
2383
  -1
2166
2384
  /* HOISTED */
2167
- ));
2168
- var _hoisted_8 = ["id"];
2169
- var _hoisted_9 = { class: "live-example__code-languages" };
2170
- var _hoisted_10 = { class: "fieldset radio-button-group radio-button-group--horizontal" };
2171
- var _hoisted_11 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ (0, import_vue3.createElementVNode)(
2172
- "legend",
2173
- { class: "label fieldset__label" },
2174
- "Kodspr\xE5k",
2175
- -1
2176
- /* HOISTED */
2177
- ));
2178
- var _hoisted_12 = { class: "fieldset__content radio-button-group__content" };
2179
- var _hoisted_13 = {
2385
+ );
2386
+ var _hoisted_72 = [
2387
+ _hoisted_62
2388
+ ];
2389
+ var _hoisted_82 = { class: "live-example__controls" };
2390
+ var _hoisted_92 = {
2180
2391
  key: 0,
2181
- class: "radio-button"
2392
+ class: "live-example__code"
2182
2393
  };
2183
- var _hoisted_14 = ["id"];
2184
- var _hoisted_15 = ["for"];
2185
- var _hoisted_16 = { class: "radio-button" };
2186
- var _hoisted_17 = ["id"];
2187
- var _hoisted_18 = ["for"];
2188
- var _hoisted_19 = { ref: "template" };
2189
- function render(_ctx, _cache, $props, $setup, $data, $options) {
2190
- const _component_live_code = (0, import_vue3.resolveComponent)("live-code");
2191
- return (0, import_vue3.openBlock)(), (0, import_vue3.createElementBlock)("div", _hoisted_1, [
2192
- (0, import_vue3.createElementVNode)(
2394
+ function render2(_ctx, _cache, $props, $setup, $data, $options) {
2395
+ const _component_live_vue_code = (0, import_vue6.resolveComponent)("live-vue-code");
2396
+ const _component_live_example_sourcecode = (0, import_vue6.resolveComponent)("live-example-sourcecode");
2397
+ return (0, import_vue6.openBlock)(), (0, import_vue6.createElementBlock)("div", _hoisted_16, [
2398
+ (0, import_vue6.createElementVNode)(
2193
2399
  "div",
2194
- _hoisted_2,
2400
+ _hoisted_22,
2195
2401
  [
2196
- (0, import_vue3.createVNode)(_component_live_code, {
2197
- components: _ctx.components,
2198
- template: _ctx.template,
2199
- livedata: _ctx.livedata,
2200
- livemethods: _ctx.livemethods
2201
- }, null, 8, ["components", "template", "livedata", "livemethods"])
2402
+ _ctx.templateLanguage === "vue" ? ((0, import_vue6.openBlock)(), (0, import_vue6.createElementBlock)("div", _hoisted_32, [
2403
+ (0, import_vue6.createVNode)(_component_live_vue_code, {
2404
+ components: _ctx.components,
2405
+ template: _ctx.template,
2406
+ livedata: _ctx.livedata,
2407
+ livemethods: _ctx.livemethods
2408
+ }, null, 8, ["components", "template", "livedata", "livemethods"])
2409
+ ])) : _ctx.templateLanguage === "html" ? ((0, import_vue6.openBlock)(), (0, import_vue6.createElementBlock)(
2410
+ import_vue6.Fragment,
2411
+ { key: 1 },
2412
+ [
2413
+ (0, import_vue6.createCommentVNode)(" eslint-disable-next-line vue/no-v-html -- expected to show rendered html "),
2414
+ (0, import_vue6.createElementVNode)("div", { innerHTML: _ctx.template }, null, 8, _hoisted_42)
2415
+ ],
2416
+ 2112
2417
+ /* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */
2418
+ )) : ((0, import_vue6.openBlock)(), (0, import_vue6.createElementBlock)("div", _hoisted_52, [..._hoisted_72]))
2202
2419
  ],
2203
2420
  512
2204
2421
  /* NEED_PATCH */
2205
2422
  ),
2206
- (0, import_vue3.createElementVNode)("div", _hoisted_3, [
2207
- (0, import_vue3.renderSlot)(_ctx.$slots, "default", {}, void 0, true)
2423
+ (0, import_vue6.createElementVNode)("div", _hoisted_82, [
2424
+ (0, import_vue6.renderSlot)(_ctx.$slots, "default")
2208
2425
  ]),
2209
- (0, import_vue3.createElementVNode)("div", _hoisted_4, [
2210
- (0, import_vue3.createElementVNode)("div", _hoisted_5, [
2211
- (0, import_vue3.createElementVNode)("button", {
2212
- type: "button",
2213
- class: "button button--discrete",
2214
- "aria-controls": _ctx.idPrefix + "-code-expand",
2215
- "aria-expanded": _ctx.codeExpand.isOpen ? "true" : "false",
2216
- onClick: _cache[0] || (_cache[0] = (...args) => _ctx.onToggleCode && _ctx.onToggleCode(...args))
2217
- }, [
2218
- _hoisted_7,
2219
- (0, import_vue3.createTextVNode)(
2220
- " " + (0, import_vue3.toDisplayString)(_ctx.codeToggleText),
2221
- 1
2222
- /* TEXT */
2223
- )
2224
- ], 8, _hoisted_6)
2225
- ]),
2226
- (0, import_vue3.createElementVNode)("div", {
2227
- id: _ctx.idPrefix + "-code-expand",
2228
- ref: "expandable",
2229
- class: "collapsed"
2230
- }, [
2231
- (0, import_vue3.createElementVNode)("div", _hoisted_9, [
2232
- (0, import_vue3.createElementVNode)("fieldset", _hoisted_10, [
2233
- _hoisted_11,
2234
- (0, import_vue3.createElementVNode)("div", _hoisted_12, [
2235
- _ctx.isVue ? ((0, import_vue3.openBlock)(), (0, import_vue3.createElementBlock)("div", _hoisted_13, [
2236
- (0, import_vue3.withDirectives)((0, import_vue3.createElementVNode)("input", {
2237
- id: _ctx.idPrefix + "-lang-vue",
2238
- "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => _ctx.codeLanguage = $event),
2239
- type: "radio",
2240
- class: "radio-button__input",
2241
- name: "code",
2242
- value: "vue"
2243
- }, null, 8, _hoisted_14), [
2244
- [import_vue3.vModelRadio, _ctx.codeLanguage]
2245
- ]),
2246
- (0, import_vue3.createElementVNode)("label", {
2247
- for: _ctx.idPrefix + "-lang-vue",
2248
- class: "radio-button__label"
2249
- }, " Vue ", 8, _hoisted_15)
2250
- ])) : (0, import_vue3.createCommentVNode)("v-if", true),
2251
- (0, import_vue3.createElementVNode)("div", _hoisted_16, [
2252
- (0, import_vue3.withDirectives)((0, import_vue3.createElementVNode)("input", {
2253
- id: _ctx.idPrefix + "-lang-html",
2254
- "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => _ctx.codeLanguage = $event),
2255
- type: "radio",
2256
- class: "radio-button__input",
2257
- name: "code",
2258
- value: "html"
2259
- }, null, 8, _hoisted_17), [
2260
- [import_vue3.vModelRadio, _ctx.codeLanguage]
2261
- ]),
2262
- (0, import_vue3.createElementVNode)("label", {
2263
- for: _ctx.idPrefix + "-lang-html",
2264
- class: "radio-button__label"
2265
- }, " HTML ", 8, _hoisted_18)
2266
- ])
2267
- ])
2268
- ])
2269
- ]),
2270
- (0, import_vue3.createElementVNode)(
2271
- "pre",
2272
- _hoisted_19,
2273
- null,
2274
- 512
2275
- /* NEED_PATCH */
2276
- )
2277
- ], 8, _hoisted_8)
2278
- ])
2426
+ _ctx.exampleElement ? ((0, import_vue6.openBlock)(), (0, import_vue6.createElementBlock)("div", _hoisted_92, [
2427
+ (0, import_vue6.createVNode)(_component_live_example_sourcecode, {
2428
+ element: _ctx.exampleElement,
2429
+ template: _ctx.template,
2430
+ "template-language": _ctx.templateLanguage
2431
+ }, null, 8, ["element", "template", "template-language"])
2432
+ ])) : (0, import_vue6.createCommentVNode)("v-if", true)
2279
2433
  ]);
2280
2434
  }
2281
2435
 
2282
2436
  // src/LiveExample.vue
2283
- LiveExample_default.render = render;
2437
+ LiveExample_default.render = render2;
2284
2438
  LiveExample_default.__file = "src/LiveExample.vue";
2285
- LiveExample_default.__scopeId = "data-v-f5e7ab48";
2286
2439
  var LiveExample_default2 = LiveExample_default;
2287
- // Annotate the CommonJS export names for ESM import in node:
2288
- 0 && (module.exports = {
2289
- LiveExample
2290
- });