@forsakringskassan/docs-live-example 1.4.1 → 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,8 +1620,149 @@ __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
1767
  var import_standalone = __toESM(require("prettier/standalone"));
1627
1768
  var import_parser_html = __toESM(require("prettier/parser-html"));
@@ -1878,10 +2019,224 @@ function stripComments(html) {
1878
2019
  return html.replace(commentPattern, "");
1879
2020
  }
1880
2021
 
1881
- // src/LiveCode.ts
1882
- var import_vue = require("vue");
1883
- var LiveCode_default = (0, import_vue.defineComponent)({
1884
- 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",
1885
2240
  props: {
1886
2241
  template: {
1887
2242
  type: String,
@@ -1901,8 +2256,12 @@ var LiveCode_default = (0, import_vue.defineComponent)({
1901
2256
  }
1902
2257
  },
1903
2258
  render() {
1904
- const renderFunction = (0, import_vue.compile)(this.template);
1905
- 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)(
1906
2265
  {
1907
2266
  name: "LiveComponent",
1908
2267
  data() {
@@ -1927,124 +2286,32 @@ var LiveCode_default = (0, import_vue.defineComponent)({
1927
2286
  }
1928
2287
  });
1929
2288
 
1930
- // src/expand-animation.ts
1931
- var DURATION = 400;
1932
- var ClassNames = {
1933
- EXPANDING: "expanding",
1934
- COLLAPSING: "collapsing"
1935
- };
1936
- var prefersReducedMotion = window.matchMedia("(prefers-reduced-motion)");
1937
- var useAnimation = !prefersReducedMotion.matches;
1938
- prefersReducedMotion.addEventListener("change", (event) => {
1939
- useAnimation = !event.matches;
1940
- });
1941
- function expandAnimation(element) {
1942
- let animation = null;
1943
- let isOpen = false;
1944
- let isClosing = false;
1945
- let isExpanding = false;
1946
- return {
1947
- get isOpen() {
1948
- return isOpen;
1949
- },
1950
- toggle() {
1951
- if (useAnimation) {
1952
- element.style.overflow = "hidden";
1953
- if (isExpanding || isOpen) {
1954
- isOpen = false;
1955
- shrink();
1956
- } else if (isClosing || !isOpen) {
1957
- isOpen = true;
1958
- open();
1959
- }
1960
- return;
1961
- }
1962
- if (isOpen) {
1963
- isOpen = false;
1964
- element.setAttribute("aria-expanded", "false");
1965
- } else {
1966
- isOpen = true;
1967
- element.setAttribute("aria-expanded", "true");
1968
- }
1969
- }
1970
- };
1971
- function shrink() {
1972
- isClosing = true;
1973
- const startHeight = `${element.offsetHeight}px`;
1974
- const endHeight = `0px`;
1975
- element.classList.add(ClassNames.COLLAPSING);
1976
- if (animation) {
1977
- animation.cancel();
1978
- }
1979
- animation = element.animate(
1980
- {
1981
- height: [startHeight, endHeight]
1982
- },
1983
- {
1984
- duration: DURATION,
1985
- easing: "ease-in-out"
1986
- }
1987
- );
1988
- animation.onfinish = () => {
1989
- onAnimationFinish(false);
1990
- };
1991
- animation.oncancel = () => {
1992
- element.classList.remove(ClassNames.COLLAPSING);
1993
- isClosing = false;
1994
- };
1995
- }
1996
- function open() {
1997
- let currentHeight = 0;
1998
- if (animation) {
1999
- currentHeight = element.getBoundingClientRect().height;
2000
- }
2001
- element.setAttribute("aria-expanded", "true");
2002
- window.requestAnimationFrame(() => expand(currentHeight));
2003
- }
2004
- function expand(currentHeight) {
2005
- isExpanding = true;
2006
- if (animation) {
2007
- animation.cancel();
2008
- element.style.height = "";
2009
- }
2010
- const startHeight = `${currentHeight}px`;
2011
- const endHeight = `${element.offsetHeight}px`;
2012
- element.classList.add(ClassNames.EXPANDING);
2013
- animation = element.animate(
2014
- {
2015
- height: [startHeight, endHeight]
2016
- },
2017
- {
2018
- duration: DURATION,
2019
- easing: "ease-in-out"
2020
- }
2021
- );
2022
- animation.onfinish = () => {
2023
- onAnimationFinish(true);
2024
- };
2025
- animation.oncancel = () => {
2026
- element.classList.remove(ClassNames.EXPANDING);
2027
- isExpanding = false;
2028
- };
2029
- }
2030
- function onAnimationFinish(open2) {
2031
- element.setAttribute("aria-expanded", open2 ? "true" : "false");
2032
- animation = null;
2033
- isClosing = false;
2034
- isExpanding = false;
2035
- element.classList.remove(ClassNames.EXPANDING);
2036
- element.classList.remove(ClassNames.COLLAPSING);
2037
- element.style.height = "";
2038
- element.style.overflow = "";
2039
- }
2040
- }
2041
-
2042
2289
  // sfc-script:/home/runner/work/docs-live-example/docs-live-example/src/LiveExample.vue?type=script
2043
- var idCounter = 1;
2044
- var LiveExample_default = (0, import_vue2.defineComponent)({
2290
+ var LiveExample_default = (0, import_vue5.defineComponent)({
2045
2291
  name: "LiveExample",
2046
- components: { LiveCode: LiveCode_default },
2292
+ components: { LiveExampleSourcecode: LiveExampleSourcecode_default2, LiveVueCode: live_vue_code_default },
2047
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
+ },
2048
2315
  template: {
2049
2316
  type: String,
2050
2317
  required: true
@@ -2073,220 +2340,100 @@ var LiveExample_default = (0, import_vue2.defineComponent)({
2073
2340
  },
2074
2341
  data() {
2075
2342
  return {
2076
- idPrefix: `live-example-${idCounter++}`,
2077
- codeLanguage: "html",
2078
- codeExpand: {
2079
- isOpen: false,
2080
- toggle() {
2081
- }
2082
- }
2343
+ /** Language declared by parent element via `data-language`, if any */
2344
+ parentLanguage: "",
2345
+ exampleElement: void 0
2083
2346
  };
2084
2347
  },
2085
2348
  computed: {
2086
- isVue() {
2087
- return Object.keys(this.components).length > 0;
2088
- },
2089
- codeToggleText() {
2090
- return this.codeExpand.isOpen ? "D\xF6lj kod" : "Visa kod";
2091
- },
2092
- exampleElement() {
2093
- return this.$refs.example;
2094
- },
2095
- expandableElement() {
2096
- return this.$refs.expandable;
2097
- },
2098
- templateElement() {
2099
- return this.$refs.template;
2100
- }
2101
- },
2102
- watch: {
2103
- template: {
2104
- immediate: false,
2105
- handler() {
2106
- this.compileCode();
2349
+ templateLanguage() {
2350
+ if (this.language !== "auto") {
2351
+ return this.language;
2107
2352
  }
2108
- },
2109
- codeLanguage: {
2110
- immediate: false,
2111
- handler() {
2112
- this.compileCode();
2353
+ if (this.parentLanguage) {
2354
+ return this.parentLanguage;
2113
2355
  }
2356
+ const hasChildComponents = Object.keys(this.components).length > 0;
2357
+ return hasChildComponents ? "vue" : "html";
2114
2358
  }
2115
2359
  },
2116
2360
  mounted() {
2117
- if (this.isVue) {
2118
- this.codeLanguage = "vue";
2119
- }
2120
- this.codeExpand = expandAnimation(this.expandableElement);
2121
- this.compileCode();
2122
- },
2123
- methods: {
2124
- onToggleCode() {
2125
- this.codeExpand.toggle();
2126
- },
2127
- compileCode() {
2128
- switch (this.codeLanguage) {
2129
- case "vue":
2130
- this.compileVue();
2131
- break;
2132
- case "html":
2133
- this.compileHTML();
2134
- break;
2135
- }
2136
- },
2137
- async compileVue() {
2138
- const { templateElement } = this;
2139
- templateElement.innerHTML = await highlight(this.template);
2140
- },
2141
- async compileHTML() {
2142
- await this.$nextTick();
2143
- const { exampleElement, templateElement } = this;
2144
- const html = exampleElement.innerHTML;
2145
- const uncommented = stripComments(html);
2146
- templateElement.innerHTML = await highlight(uncommented);
2361
+ const parent = this.$el.closest("[data-language]");
2362
+ if (parent) {
2363
+ this.parentLanguage = parent.dataset.language ?? "";
2147
2364
  }
2365
+ this.exampleElement = this.$refs.example;
2148
2366
  }
2149
2367
  });
2150
2368
 
2151
2369
  // sfc-template:/home/runner/work/docs-live-example/docs-live-example/src/LiveExample.vue?type=template
2152
- var import_vue3 = require("vue");
2153
- var _withScopeId = (n) => ((0, import_vue3.pushScopeId)("data-v-f5e7ab48"), n = n(), (0, import_vue3.popScopeId)(), n);
2154
- var _hoisted_1 = { class: "live-example__container" };
2155
- var _hoisted_2 = {
2370
+ var import_vue6 = require("vue");
2371
+ var _hoisted_16 = { class: "live-example__container" };
2372
+ var _hoisted_22 = {
2156
2373
  ref: "example",
2157
2374
  class: "live-example__example"
2158
2375
  };
2159
- var _hoisted_3 = { class: "live-example__controls" };
2160
- var _hoisted_4 = { class: "live-example__code" };
2161
- var _hoisted_5 = { class: "live-example__code-toggle" };
2162
- var _hoisted_6 = ["aria-controls", "aria-expanded"];
2163
- var _hoisted_7 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ (0, import_vue3.createElementVNode)(
2164
- "i",
2165
- { 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",
2166
2381
  null,
2382
+ "Unknown language, cannot render example",
2167
2383
  -1
2168
2384
  /* HOISTED */
2169
- ));
2170
- var _hoisted_8 = ["id"];
2171
- var _hoisted_9 = { class: "live-example__code-languages" };
2172
- var _hoisted_10 = { class: "fieldset radio-button-group radio-button-group--horizontal" };
2173
- var _hoisted_11 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ (0, import_vue3.createElementVNode)(
2174
- "legend",
2175
- { class: "label fieldset__label" },
2176
- "Kodspr\xE5k",
2177
- -1
2178
- /* HOISTED */
2179
- ));
2180
- var _hoisted_12 = { class: "fieldset__content radio-button-group__content" };
2181
- var _hoisted_13 = {
2385
+ );
2386
+ var _hoisted_72 = [
2387
+ _hoisted_62
2388
+ ];
2389
+ var _hoisted_82 = { class: "live-example__controls" };
2390
+ var _hoisted_92 = {
2182
2391
  key: 0,
2183
- class: "radio-button"
2392
+ class: "live-example__code"
2184
2393
  };
2185
- var _hoisted_14 = ["id"];
2186
- var _hoisted_15 = ["for"];
2187
- var _hoisted_16 = { class: "radio-button" };
2188
- var _hoisted_17 = ["id"];
2189
- var _hoisted_18 = ["for"];
2190
- var _hoisted_19 = { ref: "template" };
2191
- function render(_ctx, _cache, $props, $setup, $data, $options) {
2192
- const _component_live_code = (0, import_vue3.resolveComponent)("live-code");
2193
- return (0, import_vue3.openBlock)(), (0, import_vue3.createElementBlock)("div", _hoisted_1, [
2194
- (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)(
2195
2399
  "div",
2196
- _hoisted_2,
2400
+ _hoisted_22,
2197
2401
  [
2198
- (0, import_vue3.createVNode)(_component_live_code, {
2199
- components: _ctx.components,
2200
- template: _ctx.template,
2201
- livedata: _ctx.livedata,
2202
- livemethods: _ctx.livemethods
2203
- }, 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]))
2204
2419
  ],
2205
2420
  512
2206
2421
  /* NEED_PATCH */
2207
2422
  ),
2208
- (0, import_vue3.createElementVNode)("div", _hoisted_3, [
2209
- (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")
2210
2425
  ]),
2211
- (0, import_vue3.createElementVNode)("div", _hoisted_4, [
2212
- (0, import_vue3.createElementVNode)("div", _hoisted_5, [
2213
- (0, import_vue3.createElementVNode)("button", {
2214
- type: "button",
2215
- class: "button button--discrete",
2216
- "aria-controls": _ctx.idPrefix + "-code-expand",
2217
- "aria-expanded": _ctx.codeExpand.isOpen ? "true" : "false",
2218
- onClick: _cache[0] || (_cache[0] = (...args) => _ctx.onToggleCode && _ctx.onToggleCode(...args))
2219
- }, [
2220
- _hoisted_7,
2221
- (0, import_vue3.createTextVNode)(
2222
- " " + (0, import_vue3.toDisplayString)(_ctx.codeToggleText),
2223
- 1
2224
- /* TEXT */
2225
- )
2226
- ], 8, _hoisted_6)
2227
- ]),
2228
- (0, import_vue3.createElementVNode)("div", {
2229
- id: _ctx.idPrefix + "-code-expand",
2230
- ref: "expandable",
2231
- class: "collapsed"
2232
- }, [
2233
- (0, import_vue3.createElementVNode)("div", _hoisted_9, [
2234
- (0, import_vue3.createElementVNode)("fieldset", _hoisted_10, [
2235
- _hoisted_11,
2236
- (0, import_vue3.createElementVNode)("div", _hoisted_12, [
2237
- _ctx.isVue ? ((0, import_vue3.openBlock)(), (0, import_vue3.createElementBlock)("div", _hoisted_13, [
2238
- (0, import_vue3.withDirectives)((0, import_vue3.createElementVNode)("input", {
2239
- id: _ctx.idPrefix + "-lang-vue",
2240
- "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => _ctx.codeLanguage = $event),
2241
- type: "radio",
2242
- class: "radio-button__input",
2243
- name: "code",
2244
- value: "vue"
2245
- }, null, 8, _hoisted_14), [
2246
- [import_vue3.vModelRadio, _ctx.codeLanguage]
2247
- ]),
2248
- (0, import_vue3.createElementVNode)("label", {
2249
- for: _ctx.idPrefix + "-lang-vue",
2250
- class: "radio-button__label"
2251
- }, " Vue ", 8, _hoisted_15)
2252
- ])) : (0, import_vue3.createCommentVNode)("v-if", true),
2253
- (0, import_vue3.createElementVNode)("div", _hoisted_16, [
2254
- (0, import_vue3.withDirectives)((0, import_vue3.createElementVNode)("input", {
2255
- id: _ctx.idPrefix + "-lang-html",
2256
- "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => _ctx.codeLanguage = $event),
2257
- type: "radio",
2258
- class: "radio-button__input",
2259
- name: "code",
2260
- value: "html"
2261
- }, null, 8, _hoisted_17), [
2262
- [import_vue3.vModelRadio, _ctx.codeLanguage]
2263
- ]),
2264
- (0, import_vue3.createElementVNode)("label", {
2265
- for: _ctx.idPrefix + "-lang-html",
2266
- class: "radio-button__label"
2267
- }, " HTML ", 8, _hoisted_18)
2268
- ])
2269
- ])
2270
- ])
2271
- ]),
2272
- (0, import_vue3.createElementVNode)(
2273
- "pre",
2274
- _hoisted_19,
2275
- null,
2276
- 512
2277
- /* NEED_PATCH */
2278
- )
2279
- ], 8, _hoisted_8)
2280
- ])
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)
2281
2433
  ]);
2282
2434
  }
2283
2435
 
2284
2436
  // src/LiveExample.vue
2285
- LiveExample_default.render = render;
2437
+ LiveExample_default.render = render2;
2286
2438
  LiveExample_default.__file = "src/LiveExample.vue";
2287
- LiveExample_default.__scopeId = "data-v-f5e7ab48";
2288
2439
  var LiveExample_default2 = LiveExample_default;
2289
- // Annotate the CommonJS export names for ESM import in node:
2290
- 0 && (module.exports = {
2291
- LiveExample
2292
- });