djledda.de main
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 2 месеца
преди 2 месеца
преди 2 месеца
преди 2 месеца
преди 2 месеца
преди 2 месеца
преди 2 месеца
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { type InjectionKey, inject } from 'vue';
  2. import useDJSSRContext from "@/useDJSSRContext.ts";
  3. export function gid(id: string, doc: (Document | ShadowRoot) | undefined) {
  4. return ((doc ?? document).getElementById(id));
  5. }
  6. export function qs(query: string, sub: (HTMLElement | ShadowRoot) | undefined) {
  7. return ((sub ?? document).querySelector(query));
  8. }
  9. export function qsa(query: string, sub?: (HTMLElement | ShadowRoot) | undefined) {
  10. return ((sub ?? document).querySelectorAll(query));
  11. }
  12. export function h<T extends keyof HTMLElementTagNameMap>(
  13. tag: T,
  14. opts?: Partial<HTMLElementTagNameMap[T]> | undefined,
  15. children?: Node[],
  16. ) {
  17. const newEl = Object.assign(document.createElement(tag), opts ?? {});
  18. if (children) {
  19. newEl.append(...children);
  20. }
  21. return newEl;
  22. }
  23. export function html(strs: TemplateStringsArray, ...vals: string[]) {
  24. let result = strs[0];
  25. for (let i = 1; i < strs.length; i++) {
  26. result += vals[i] + strs[i];
  27. }
  28. const template = document.createElement("template");
  29. template.innerHTML = result;
  30. return template;
  31. }
  32. export function css(strs: TemplateStringsArray, ...vals: string[]) {
  33. let result = strs[0];
  34. for (let i = 1; i < strs.length; i++) {
  35. result += vals[i] + strs[i];
  36. }
  37. return result;
  38. }
  39. export const cssRegistry = Symbol('css-registry') as InjectionKey<Set<string>>;
  40. export function addCSS(key: string, css: string) {
  41. const context = useDJSSRContext();
  42. if (context && !context.styles[key]) {
  43. context.styles[key] = css;
  44. } else {
  45. const registry = inject(cssRegistry);
  46. if (!registry?.has(key)) {
  47. const stylesheet = new CSSStyleSheet();
  48. stylesheet.replace(css);
  49. document.adoptedStyleSheets.push(stylesheet);
  50. }
  51. }
  52. }
  53. /*
  54. export class DJElement extends HTMLElement {
  55. static styles: CSSStyleSheet;
  56. static template: HTMLTemplateElement;
  57. root: ShadowRoot;
  58. constructor() {
  59. super();
  60. const statics = this.constructor as typeof DJElement;
  61. this.root = this.attachShadow({ mode: "open" });
  62. this.root.appendChild(statics.template.content.cloneNode(true));
  63. this.root.adoptedStyleSheets = statics.styles ? [statics.styles] : [];
  64. }
  65. }
  66. */